Detecting Form Closure when X is clicked

  • Thread starter Thread starter peek
  • Start date Start date
P

peek

This has probably be asked before but I'm trying to trap the event
before a user closes the main form of VB.NET application to show an
error message if there are unsaved changes. Can anyone point me in
the right direction?
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://wwww.HotCodecs.com
*---------------------------------*
 
Use the Form.Closing event. This will work if they hit F4 or the X button.

Chris

peek said:
This has probably be asked before but I'm trying to trap the event
before a user closes the main form of VB.NET application to show an
error message if there are unsaved changes. Can anyone point me in
the right direction?
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://wwww.HotCodecs.com
*---------------------------------*
 
peek said:
I'm trying to trap the event before a user closes the main form
of VB.NET application to show an
error message if there are unsaved changes.

\\\
Imports System.ComponentModel
..
..
..
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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top