Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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?
[no name] 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

Try below code:
VB
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:
http://stackoverflow.com/questions/2256869/vb-net-abort-formclosing[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900