Question customize close "x" button

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
Hello all,

Does anyone know how to get a messagebox appear if the user clicks the "x" button in the upper right corner of a form?

I would like a messagebox that says "Are you sure you would like to exit?" and have a yes / no button....

Thanks in advanced

daveofgv

I am using vb.net 2008 pro
 
FormClosing event. Use e.Cancel if the user clicks No.
 
Thank you.....

I used:

VB.NET:
 Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MessageBox.Show("Are you sure you would like to close?", "Form Close", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

Works like a charm....

Thanks again

daveofgv
 
Back
Top