Does anyone have an idea to write code, if the user clicks the external form of the window, does the form automatically close? Ie, I had two forms, when I show form2, and then I click it, form 2 will be closed.
Does it help? Try the first two solutions, one of which should work for you.
Winforms: closing a modal dialog when pressed outside of a dialog
You can just use the built-in LostFocus event for a form like this
LostFocus
Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As EventArgs) _ Handles Me.LostFocus Me.Close() End Sub