You are browsing VB.NET Forum.
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.Show("Dali ste sigurni da zelite prekinuti rad aplikacije", "Matematicar", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then Me.Close() ElseIf Windows.Forms.DialogResult.Cancel Then End If End Sub
How to stop form closing
,

basically placed by kevininstructorAs follows
Code:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Not MessageBox.Show("Dali ste sigurni da zelite prekinuti rad aplikacije", "Matematicar", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = 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 isn't 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 isn't displaying good practice(s) either.
, When I use e.Cancel = True I get this:
Error1'cancel' isn't a member of 'System.EventArgs'.C: Users moj racunar documents visual studio 2010 Projects Matematicar Matematicar Form1.vb13113Matematicar
, You get that error message because I am assuming that you do not have the e.Cancel = True in the form_closing event. Click any where on your 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 snippet in the formclosing_event.
Posted On: Tuesday, November 06, 2012 Total Views: 29
View Complete with Replies


Hi,

This webpage contains content related to VB.NET. If question related to "ConfirmationBox while leaving form" is not helpful or you didn't find the question or answer you were looking for then you can ask a new question through contact form. Our development Team will be happy to help you. This article was posted on Tuesday, November 06, 2012 and having 29 views till Thursday, July 31, 2014.

Thank You