SEARCH YOUR SOLUTION HERE  

ConfirmationBox while leaving form

My code snippet:
vb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object ByVal e As System.EventArgs) Handles MyBase.Closing If MessageBox.Display("Dali ste sigurni da zelite prekinuti rad aplikacije", "Matematicar", MessageBoxButtons.OKCancel, MessageBoxIcon.Info) = Windows.Forms.DialogResult.OK Then Me.Close() ElseIf Windows.Forms.DialogResult.Cancel Then End If End Sub
How can i stop form closing
,

Basically Placed by kevininstructorGiven bellow
Code:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Not MessageBox.Display("Dali ste sigurni da zelite prekinuti rad aplikacije", "Matematicar", MessageBoxButtons.OKCancel, MessageBoxIcon.Info) = Windows.Forms.DialogResult.OK Then
e.Cancel = True
End If
End Sub What if the form is closing due to windows shutdown logoff
Check e.CloseReason to make sure it is not closing because of a system reason before displaying a "confirm close" prompt.
,

Basically Placed by kevininstructorTrue but the OP wasn't that specific
True, but not comprising a comment to that effect is not displaying good practice(s) either.
, When I use e.Cancel = True I receive this:
Error message1'cancel' is not a member of 'System.EventArgs'.C: Users moj racunar documents visual studio 2010 Projects Matematicar Matematicar Form1.vb13113Matematicar
, U receive that error message because I am assuming that u do not have the e.Cancel = True in the form_closing event. Click any where on ur form to bring up the form's properties, then click on the lightning bolt. Scroll up and doubleclick on the formclosing. Finally paste that code in the formclosing_event.
Posted On: Tuesday, November 6, 2012 Total Views: 4
View Complete with Replies