Results 1 to 12 of 12

Thread: how does the form Closing event work

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    BC,Canada
    Posts
    15

    how does the form Closing event work

    I just using vb .NET and i'm familiar with vb 6.0 event QueryUnload, but how do you implement the closing event from vb .NET.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The closing event works basically like the Form_Unload event or QueryUnload event but there is no known way to catch the reason the form is closing. .NET doesn't have anything like the UnloadMode in VB6.

  3. #3
    Member
    Join Date
    Sep 2002
    Posts
    35
    the closing event is

    Private Sub form1_closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closing

    that what you wanted?

    J

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Edneeis
    The closing event works basically like the Form_Unload event or QueryUnload event but there is no known way to catch the reason the form is closing. .NET doesn't have anything like the UnloadMode in VB6.
    actually I had the same question a few days ago and I asked it in GotDotNet forums, I couldnt find the answer. But there is a way to do it. This is from MSDN: "If it is necessary to determine why the form is closing, you will need to create an overloaded version of the Closing event with custom code to determine the caller."

    so there is a way but I dont know how to overload this thing the way it says it
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What MSDN article does that come from? I really miss that feature especially for some TrayIcon apps I have.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    BC,Canada
    Posts
    15
    i found out a way to get work. In the "Windows Form Designer generated code" the is a dispose function. i put my code there.

  7. #7
    New Member
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    9
    I am not sure but, I think this is what you are looking for. It uses the new class messagebox, the old msgbox is still there but it in the Microsoft.VisualBasic namespace. I try to use the SYSTEM namespace first you know onward and upward.

    Anyway this works perfect, you can stop the form from closing. The old way was with a byref variable, but we are using objects now.

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

    Dim Response As DialogResult

    Response = MessageBox.Show("Are you sure you want to Quit?", "Finishing", MsgBoxStyle.YesNo)

    If Response = DialogResult.No Then e.Cancel = True

    End Sub
    A Jeepers point of view
    Get In, Sit Down, Shut Up and Hold On!

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    overloading

    related to overloading
    Private Sub form1_closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closing


    Overloading lets a function vary its behavior based on its input arguments . vb.net will have multiple functions with the same name, but with different argument lists.

    Private Sub form1_closing(ByVal sender As Integer , ByVal e As System.EventArgs) Handles MyBase.Closing (as an example)
    Last edited by Pirate; Sep 26th, 2002 at 10:19 PM.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    How do you get the OS or what not to tell you why the form is closing like the old UnloadMode. For instance was it the x close button in the corner of the form? Was it the Me.Close method in your code? Was it because the OS is shuting down? The last one is really the most important.

  10. #10
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Edneeis
    How do you get the OS or what not to tell you why the form is closing like the old UnloadMode. For instance was it the x close button in the corner of the form? Was it the Me.Close method in your code? Was it because the OS is shuting down? The last one is really the most important.
    well take a lookie at these two, they dont help much, but maybe you can ask them a question so that they could help


    http://www.gotdotnet.com/Community/M....aspx?id=40651

    and (C# forums):

    http://www.gotdotnet.com/Community/M....aspx?id=40717
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I can detect the X button close and the me.close (I think) but haven't found how to track the System closing. The way I have is somewhat hackish, its easy to implement but not the prettiest. I'll post it when I figure the last one out. Basically you can use the Application.AddMessageFilter to filter Window messages like subclassing. So then I just watch for the NCMouseDown event with wParam 20 which is the mousedown event for the form's close button. If I catch it then I don't forward it instead I call an alternate Closing event and pass the unloadmode in the eventargs.

  12. #12

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