Which event fires when a user clicks the X to close a window...

Posted on 2005-04-12
Last Modified: 2010-04-23
In vb there was the unlaod event what is the equal to that in, i want to check before i despose the
window if there is any pendeng changes which need to be saved..

Question by:AlexPonnath
    LVL 1

    Expert Comment

    You could try Form.Closing

    Author Comment

    but how do i cancel the closing once it hits the closing event ???

    lets say i want to ask the customer if he is sure he doesnt want to save the data, if he says he wants to save the data before
    how can i tell the form to abort the close..
    LVL 13

    Expert Comment

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
            <execute your code>
        End Sub
    LVL 32

    Accepted Solution

    "The Closing event occurs as the form is being closed. When a form is closed, all resources created within the object are released and the form is disposed. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your event handler to true."


    Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

            If (MessageBox.Show("Do you want to exit?", "My Application", _
             MessageBoxButtons.YesNo) = DialogResult.No) Then
                e.Cancel = True
            End If

        End Sub


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now