2012-01-05 42 views
0

以下代碼是我爲了顯示MsgBox而在MenuStrip上退出ITEM時單擊了它然後它會給出兩個不同的選擇是和否。如果是,則它將關閉應用程序,但如果沒有,那麼它應該保持在同一頁面上。通過Dialog VB 2010關閉選擇

沒有顯示錯誤,但它既不按鈕都在做什麼。請回到我這個。

在此先感謝!

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 

回答

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 
+0

謝謝你,乾杯 – 2012-01-05 09:00:38

0

試試這個

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