Im quiet new to vb.net and I'm trying to create a special system when a user closes a form. For my system I would like to raise the FormClosing Event manually.
-> So: How can I raise the FormClosing Event from somewhere in the code?
Info: The form is popping up as a "ShowDialog".
Thank You!
To manually force the FormClosing event you call the Close() method using the instance of the form to close.
This means that your call to Close() should be done from inside the form shown because you have used ShowDialog()
. This method is modal and doesn't return the control until the form is closed
The FormClosing event receive a FormClosingEventArgs parameter where you could find the CloseReason property. This property is an enum where you could check the reason for the closing event.
If the reason is UserClosing
then you could set the property Cancel of the FormClosingEventArgs to true (leaving the form open) and call you own procedure