Results 1 to 6 of 6

Thread: [RESOLVED] Commands on closing a window

  1. #1
    Lively Member drdress's Avatar
    Join Date
    Jul 09
    Location
    Copenhagen, Denmark
    Posts
    76

    Resolved [RESOLVED] Commands on closing a window

    Is there a way to execute some lines, when the main window (form1) is closed?

  2. #2
    Addicted Member
    Join Date
    Sep 08
    Posts
    138

    Re: Commands on closing a window

    Regiter closed event or override onclosed method.

    Closed/closing event resources:
    MSDN: closed event
    MSDN: closing event

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    Re: Commands on closing a window

    From .NET 2.0 onwards, you should be using the FormClosing and/or FormClosed events rather than the Closing and Closed events. Note that those ending with "ing" occur before the form closes and allow you to prevent it while those ending with "ed" occur after the form closes.

  4. #4
    Lively Member drdress's Avatar
    Join Date
    Jul 09
    Location
    Copenhagen, Denmark
    Posts
    76

    Re: Commands on closing a window

    Eeh. So how exactly do I write this? Like this:

    Code:
    public void FormClosing(){
       
       //Lines I want executed
       DoStuff();
    
    {

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    Re: Commands on closing a window

    It's an event, so you handle it like any other event. Select the object whose event you want to handle, open the Properties window, click the Events button and then double-click the event.

  6. #6
    Lively Member drdress's Avatar
    Join Date
    Jul 09
    Location
    Copenhagen, Denmark
    Posts
    76

    Re: Commands on closing a window

    Ahh. There it is. 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
  •