|
-
Jan 23rd, 2003, 04:11 PM
#1
Thread Starter
Hyperactive Member
Quitting an app
In my program, you can quit from a menu and the program asks you to make sure:
VB Code:
Private Sub mnuexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuexit.Click
If MsgBox("Are you sure you want to end the program?", vbYesNo, "Exit CodeBook") = 6 Then
Application.Exit()
End If
End Sub
But pressing the 'x' button just closes the app straight away, how do I catch when the user uses either?
I know it has something to do with:
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
End Sub
but I can't get it to work correctly. Any help would be appreciated.
-
Jan 23rd, 2003, 05:02 PM
#2
Member
Sounds like you want something like this.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Are you sure you want to Exit?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Application.Exit()
Else
e.Cancel = True
End If
End Sub
Harold Hoffman
-
Jan 23rd, 2003, 05:12 PM
#3
Maybe I just have backsplash from my VB6 days and the End command, but I wouldn't use Application.Exit I would close all open form instead (or actually just the main form which carries the application thread). So if that is the 'main' form of the application then just do Me.Close(). That will ensure that the other close events fire properly.
-
Jan 23rd, 2003, 05:15 PM
#4
Sleep mode
this puzzles me , which X button are you talking about (form's or dialog's) .I tested your code it's fine
-
Jan 23rd, 2003, 05:16 PM
#5
Sleep mode
What about doing so Edneeis :
Me.Dispose
Me.Close
-
Jan 23rd, 2003, 05:46 PM
#6
PowerPoster
How about instead of closing anything, you let the app do it by itself:
Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Are you sure you want to Exit?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
e.Cancel = True
End If
End Sub
-
Jan 23rd, 2003, 06:17 PM
#7
Thread Starter
Hyperactive Member
Thanks
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
|