Tags: button, code, form, forms, net, plz, sharp, telll, trap, window, windows

how to trap X button in windows form (c#)

On .Net » .Net C# (C sharp)

6,167 words with 1 Comments; publish: Thu, 22 May 2008 00:26:00 GMT; (10078.13, « »)

hi

plz tell me how to know "how window is going to close"...

i have to right code for X button of forms...

plz telll me

thanks

bye

All Comments

Leave a comment...

  • 1 Comments
    • Too lazy? Took me 2 seconds to find the events on MSDN.

      ms-help://MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemwindowsformsformclas

      sclosingtopic.htm

      and

      ms-help://MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemwindowsformsformclas

      sclosedtopic.htm

      Form.Closing Event

      See Also

      Form Class | Form Members | System.Windows.Forms Namespace | IsMdiContainer

      | OnClosing | Form Members (Visual J# Syntax) | Managed Extensions for C++

      Programming

      Requirements

      Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows

      2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

      family

      Language

      a.. C#

      b.. C++

      c.. JScript

      d.. Visual Basic

      e.. Show All

      Occurs when the form is closing.

      [Visual Basic]

      Public Event Closing As CancelEventHandler

      [C#]

      public event CancelEventHandler Closing;

      [C++]

      public: __event CancelEventHandler* Closing;

      [JScript] In JScript, you can handle the events defined by a class, but you

      cannot define your own.

      Event Data

      The event handler receives an argument of type CancelEventArgs containing

      data related to this event. The following CancelEventArgs property provides

      information specific to this event.

      Property Description

      Cancel Gets or sets a value indicating whether the event should be

      canceled.

      Remarks

      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.

      When a form is displayed as a modal dialog box, clicking the Close button

      (the button with an X at the upper-right corner of the form) causes the form

      to be hidden and the DialogResult property to be set to DialogResult.Cancel.

      You can override the value assigned to the DialogResult property when the

      user clicks the Close button by setting the DialogResult property in an

      event handler for the Closing event of the form.

      Note When the Close method is called on a Form displayed as a modeless

      window, you cannot call the Show method to make the form visible, because

      the form's resources have already been released. To hide a form and then

      make it visible, use the Control.Hide method.

      CAUTION The Form.Closed and Form.Closing events are not raised when the

      Application.Exit method is called to exit your application. If you have

      validation code in either of these events that must be executed, you should

      call the Form.Close method for each open form individually before calling

      the Exit method.

      If the form is an MDI parent form, the Closing events of all MDI child forms

      are raised before the MDI parent form's Closing event is raised. In

      addition, the Closed events of all MDI child forms are raised before the

      Closed event of the MDI parent form is raised. Canceling the Closing event

      of an MDI child form does not prevent the Closing event of the MDI parent

      form from being raised. However, cancelling the event will set to false the

      System.Windows.Forms.ClosingEventArgs.Cancel property of the

      System.Windows.Forms.ClosingEventArgs that is passed as a parameter to the

      parent form. To force all MDI parent and child forms to close, set the

      System.Windows.Forms.ClosingEventArgs.Cancel property to false in the MDI

      parent form.

      For more information about handling events, see Consuming Events.

      Example

      Form.Closed Event

      See Also

      Form Class | Form Members | System.Windows.Forms Namespace | IsMdiContainer

      | OnClosed | Load | Form Members (Visual J# Syntax) | Managed Extensions for

      C++ Programming

      Requirements

      Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows

      2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

      family

      Language

      a.. C#

      b.. C++

      c.. JScript

      d.. Visual Basic

      e.. Show All

      Occurs when the form is closed.

      [Visual Basic]

      Public Event Closed As EventHandler

      [C#]

      public event EventHandler Closed;

      [C++]

      public: __event EventHandler* Closed;

      [JScript] In JScript, you can handle the events defined by a class, but you

      cannot define your own.

      Event Data

      The event handler receives an argument of type EventArgs.

      Remarks

      This event occurs after the form has been closed by the user or by the Close

      method of the form. To prevent a form from closing, handle the Closing event

      and set the Cancel property of the CancelEventArgs passed to your

      event-handling method to true.

      You can use this event to perform tasks such as freeing resources used by

      the form and to save information entered in the form or to update its parent

      form.

      CAUTION The Form.Closed and Form.Closing events are not raised when the

      Application.Exit method is called to exit your application. If you have

      validation code in either of these events that must be executed, you should

      call the Form.Close method for each open form individually before calling

      the Exit method.

      If the form is an MDI parent form, the Closing events of all MDI child forms

      are raised before the MDI parent form's Closing event is raised. In

      addition, the Closed events of all MDI child forms are raised before the

      Closed event of the MDI parent form is raised.

      For more information about handling events, see Consuming Events.

      "RAJ" <trajggn.net-csharp.todaysummary.com.hotmail.com> wrote in message

      news:e8$l4icXDHA.3924.net-csharp.todaysummary.com.tk2msftngp13.phx.gbl...

      > hi

      > plz tell me how to know "how window is going to close"...

      > i have to right code for X button of forms...

      > plz telll me

      > thanks

      > bye

      >

      #1; Thu, 22 May 2008 00:27:00 GMT