Windows Form Unload

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone please tell me what event gets fired when the x in the top RH
corner of a Windows Form gets clicked.
I've spent about a day trying to find this information to no avail. I am
trying to trap the event to allow the user to confirm that they wish to exit
the application.

TIA
 
Hi John,

Put this code in Form Closing event:
if (MessageBox.Show ("Exit", "exit", MessageBoxButtons.YesNo) ==
DialogResult.No)
e.Cancel = true;
 
You should trap the Closing event. The arguments supplied are a
CancelEventArgs that enable you to ask the user and cancel the close if
desired.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
John Mason said:
Can someone please tell me what event gets fired when the x in the top RH
corner of a Windows Form gets clicked.

'Closing', 'Closed' (if the form is closed).
I've spent about a day trying to find this information to no avail. I am
trying to trap the event to allow the user to confirm that they wish to
exit
the application.

\\\
Private Sub Form1_Closing( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles MyBase.Closing
If _
MsgBox( _
"Really close?", _
MsgBoxStyle.YesNo Or MsgBoxStyle.Question _
) = MsgBoxResult.No _
Then
e.Cancel = True
End If
End Sub
///
 
Back
Top