Click here to Skip to main content
13,551,032 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can I add something like msgbox in a form if close button is pressed? I mean that if the close button is pressed then a dialog appears with different choices.
Posted 20-Sep-12 2:11am
Malli_S 20-Sep-12 8:14am
What kind of choices? Which close button you're talking about? 'X' close button or a button you provided with 'Close' text on dialog?
Wes Aday 20-Sep-12 8:24am
Have a look at the events. The form closing event might be just the thing you are looking for.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try below code:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing     
       If (MessageBox.Show("Close?", "", MessageBoxButtons.YesNo) =  Windows.Forms.DialogResult.No) Then
         e.Cancel = True     
End If
End Sub

See following link for more information:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180515.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100