this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Monday, November 17, 2008

display dialog box before confirm closing of form..

in some sitation we want to display dialog box to user before closing form. Either by clicking on some button or close by pressing Alt +F4 This can be done by writing code in formClosing event.

Private Sub frmMyForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If MessageBox.Show("Change has been made to this form. Do you want to continue?", "Are you sure?", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
            e.Cancel = True
        End If
    End Sub

At, that time we just need to cancle closing event. Nothing else otherwise form will be closed whatever you have write.

No comments: