vb.net 消息框中是/否功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9181363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Yes/No function in a messagebox
提问by Jeremy F.
I want to add a yes/no function to a message box (Are you sure you want to exit?) in InfoPath 2007. If the user clicks 'Yes' the InfoPath form closes, if no, then the user is taken back to the form. From what I have read this will not happen in InfoPath. So, I added a new windows form that has the Yes/No buttons.
我想在 InfoPath 2007 中向消息框添加是/否功能(您确定要退出吗?)。如果用户单击“是”,InfoPath 表单将关闭,如果不是,则用户将返回到形式。从我所读到的,这不会发生在 InfoPath 中。因此,我添加了一个具有是/否按钮的新窗口窗体。
For the 'No' button, I have (me.close) which closes the windows form and the user is left with the InfoPath form. I need help when the user clicks 'Yes' meaning they want to close the windows form AND the InfoPath form. Below is my code so far. Many thanks in advance.
对于“否”按钮,我有 (me.close) 关闭窗口窗体,用户留下 InfoPath 窗体。当用户单击“是”意味着他们想要关闭 Windows 窗体和 InfoPath 窗体时,我需要帮助。以下是我到目前为止的代码。提前谢谢了。
Imports Microsoft.Office.InfoPath
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Diagnostics
Public Class Confirm_Close
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
Me.Close()
End Sub
Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click
Try
<need help here>
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
回答by Isuru
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
If MessageBox.Show("Do you want to exit?", "Title", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
End Sub
回答by user2444865
THe following is how i sovled this:
以下是我如何解决这个问题:
If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
' execute command
End If
回答by SAHID
If MessageBox.Show("Do you want to Exit?", "EXIT MESSAGE", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Me.Close()
End If