displaying a message box when the 'X' is clicked on the toolbar

crazymarvin

Member
Joined
Nov 22, 2006
Messages
18
Location
Belfast, UK
Programming Experience
Beginner
How would you get a yes/no message box to appear when the red 'X' was clicked on the toolbar. I asumed it would work the same as if you were putting the code behind a button only with a different event. however i can not get it so that the form wont close when the no button is clicked

This is what i had thought of:
VB.NET:
Private Sub frmPIN_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If MessageBox.Show("Are you sure you want to quit?", "Exit", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = MsgBoxResult.Yes Then Me.Close()
End Sub
 
You have to set e.Cancel = True if you don't want the closing.
 
VB.NET:
If MessageBox.Show("Are you sure you want to quit?", "Exit", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DiaglogResults.No Then e.Cancel = True
 
Back
Top