我嘗試使用表單關閉事件退出應用程序,但確認消息框出現兩次。使用FormClosing事件VB.net關閉應用程序
這是我有:
Private Sub FrmMainPlatform_FormClosing(sender As Object, e As FormClosingEventArgs) _
Handles MyClass.FormClosing
Dim result As Integer
result = MessageBox.Show("Are you want to close", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.None)
If (result = DialogResult.No) Then
e.Cancel = True
Else
Application.Exit()
End If
End Sub
我也試圖與此解決方案:
Private Sub FrmMainPlatform_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case MessageBox.Show("Are you sure you want to exit?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case Windows.Forms.DialogResult.Yes
'nothing to do here the form is already closing
Case Windows.Forms.DialogResult.No
e.Cancel = True 'cancel the form closing event
'minimize to tray/hide etc here
End Select
End Sub
的形式被關閉,但應用程序,我仍然在運行。
如果單擊yes,它會顯示兩次嗎? – dbasnett
是它出現兩次 –
這段代碼對我來說工作得很好,所以在其他地方一定有其他的東西導致了這個問題。你確定這是兩次調用的確切代碼嗎?在Select Case MessageBox.Show(「你確定要退出嗎?」,「確認」,MessageBoxButtons.YesNo,MessageBoxIcon.Question)'放置一個斷點並運行代碼。它打了兩次嗎? – Bugs