这是我的代码:
Private Sub frmName_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
If MessageBox.Show("Are you sure you want to logout?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Close()
Else
e.Cancel = True
End If
End If
End Sub
如果我点击no
,它将取消关闭表单,但是当我点击yes
时,邮件框会重复出现。我想要发生的是当我点击关闭按钮,然后单击yes
它将关闭表单。我该如何解决这个问题?
答案 0 :(得分:1)
由于表格已经结束,因此无需再次致电Close()
。以下代码应该有效:
Private Sub frmName_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
If MessageBox.Show("Are you sure you want to logout?", _
"Exit", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End If
End Sub