【发布时间】:2020-02-26 01:32:23
【问题描述】:
我目前正在尝试修复 VB.Net 中的表单关闭事件,以便当用户尝试退出表单时 txtInput1 和 txtInput2 中有文本时,它将退出并从消息框中显示警告提示。这可行,但是如果两个框中都没有任何内容,则不应显示此提示,表单应关闭。这是我到目前为止的表单关闭事件,但它不起作用:
'FormClosing Event
Private Sub MyForm_Closing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If (txtInput1.Text = "" And txtInput2.Text = "") Then
Me.Close()
End If
If MessageBox.Show("Are you sure you sure you want to exit?", "Exit", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End Sub
【问题讨论】:
-
_ 但它不起作用_ - 你怎么知道这不起作用?
-
这会导致递归吗?因为当你调用
Me.Close()时,Form_Closing事件将被触发。 ,
标签: vb.net