|
-
Nov 28th, 2002, 12:14 AM
#1
Thread Starter
Junior Member
form unload
I put this code to the Closed() event of a Form in VB.NET.
If MessageBox.Show("Would you like to exit?", "Exit", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.Exit()
Else
Cancel = 1
End If
All I want to happen is, when I click the Close Button(X) of the Form, the messagebox OK/Cancel will show and asking if you want to exit or not. If you click OK button, the form will unload. But if you click the Cancel button the Form will not unload. I tried the Cancel = 1 but it doesn’t work. Any solution for this problem.
-
Nov 28th, 2002, 02:57 AM
#2
Registered User
Soemthing like this should work....
Code:
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Really?", "", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.Exit()
Else
e.Cancel = True
End If
End Sub
If this is a subform and you dont want to end the application replace Application.Exit() wit Me.Dispose()
-
Nov 29th, 2002, 09:12 AM
#3
Lively Member
very handy: [vbcode][/vbcode]
VB.NET - VB6 - VBA - ASP - RPG(AS/400) - C++ - java - SQL
look in the help, many probs can be solved that way.
I know, i'm to lazy too.
PLEASE PUT RESOLVED IF RESOLVED!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|