通过Dialog VB 2010结束选择

时间:2012-01-05 08:40:19

标签: sql vb.net visual-studio-2010

以下代码是我为了在单击MenuStrip上的退出ITEM时显示MsgBox所做的,然后它将给出两个不同的选择是和否。如果是,那么它将关闭应用程序但如果否则则它应该保持在同一页面上。

没有显示错误,但它们都没有做任何事情。请回复我这个。

提前致谢!

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles ExitMenu.Click
    MsgBox("Are you sure you want to exit the program?", MsgBoxStyle.YesNo)
    If MsgBoxResult.Yes = True Then
        Application.Exit()
    End If

2 个答案:

答案 0 :(得分:1)

如果在vb.net中显示消息框,则调用返回结果的函数,然后将其与MsgBoxResult枚举进行比较

更改您的代码,使其如下所示:

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitMenu.Click 
If MsgBox("Are you sure you want to exit the program?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 
    Application.Exit() 
End If 

您还可以将它与MsgBoxResult枚举的整数值进行比较,对于是,该值为6:

If MsgBox("Are you sure you want to exit the program?", MsgBoxStyle.YesNo) = 6

答案 1 :(得分:0)

试试这个

 If MsgBox("Are you sure you want to exit the program?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        Application.Exit()
    End If