3

任何人都知道如何编写代码,如果用户点击窗体外的窗体,窗体将自动关闭?即,我有两个表格,当我显示 form2 然后我点击它外部时,表格 2 将关闭。

4

2 回答 2

5

Does this help? Try the first two solutions, one of which should work for you.

Winforms: Close modal dialog when clicking outside the dialog

于 2012-11-06T08:02:29.900 回答
2

您可以LostFocus像这样简单地使用表单的内置事件

Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As EventArgs) _
        Handles Me.LostFocus

    Me.Close()
End Sub
于 2012-11-06T09:20:44.960 回答