Results 1 to 7 of 7

Thread: Quitting an app

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Quitting an app

    In my program, you can quit from a menu and the program asks you to make sure:

    VB Code:
    1. Private Sub mnuexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuexit.Click
    2.         If MsgBox("Are you sure you want to end the program?", vbYesNo, "Exit CodeBook") = 6 Then
    3.             Application.Exit()
    4.         End If
    5.     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:
    1. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    2.  
    3.     End Sub
    but I can't get it to work correctly. Any help would be appreciated.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    Member
    Join Date
    Sep 2002
    Posts
    37
    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

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    this puzzles me , which X button are you talking about (form's or dialog's) .I tested your code it's fine

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What about doing so Edneeis :
    Me.Dispose
    Me.Close

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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

  7. #7

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width