Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET VB.NET programming
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 3:11am
Comments
Malli_S at 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 at 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
good
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:
http://stackoverflow.com/questions/2256869/vb-net-abort-formclosing[^]
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2014
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