How I can to disable the X button (next to Maximize and Minimize form) to don´t permit the user close the form with this button and only permit close by a specific button I.E (Close, Exit, etc)
If I'm not mistaken, JuggaloBrotha's solution as is will prevent the Form closing by any method other than Application.Exit(), which does not raise the Closing event. If you have a Form level variable, set to False by default, which you set to True when you want to close the Form, you can test this variable in the Form.Closing event handler.
VB.NET:
Private canClose As Boolean = False
Private Sub CloseForm()
Me.canClose = True
End Sub
Private Sub Form1_Closing(...) Handles MyBase.Closing
e.Cancel = Not Me.canClose
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.