System.Windows.Forms.Form.Close Method

Closes the form.

Syntax

public void Close ()

Remarks

When a form is closed, all resources created within the object are closed and the form is disposed. You can prevent the closing of a form at run time by handling the Form.Closing event and setting the System.ComponentModel.CancelEventArgs.Cancel property of the System.ComponentModel.CancelEventArgs passed as a parameter to your event handler. If the form you are closing is the startup form of your application, your application ends.

The two conditions when a form is not disposed on Close is when (1) it is part of a multiple-document interface (MDI) application, and the form is not visible; and (2) you have displayed the form using Form.ShowDialog. In these cases, you will need to call erload:System.Windows.Forms.Form.Dispose manually to mark all of the form's controls for garbage collection.

Note:

When the Form.Close method is called on a System.Windows.Forms.Form displayed as a modeless window, you cannot call the Control.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.

Note:

Prior to the dnprdnshort 2.0, 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 Application.Exit method.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0