Results 1 to 3 of 3

Thread: form unload

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    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.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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()

  3. #3
    Lively Member freightliner's Avatar
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    123
    very usefull indeed
    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
  •  



Click Here to Expand Forum to Full Width