anybody have an idea how to write a code if the user clicks outside windows form, the form will automatically close? I.e., I had two forms, when i show form2 and then i click outside of it, form 2 will closed.
Asked
Active
Viewed 5,068 times
2 Answers
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
2
You can simply utilize the LostFocus
built-in event of the Form like this
Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As EventArgs) _
Handles Me.LostFocus
Me.Close()
End Sub

Ahmad
- 12,336
- 6
- 48
- 88