Form.Close Form.Close Form.Close Form.Close Method

定义

关闭窗体。Closes the form.

public:
 void Close();
public void Close ();
member this.Close : unit -> unit
Public Sub Close ()

异常

在创建句柄时关闭了窗体。The form was closed while a handle was being created.

Activated 设置为 WindowState 时,无法从 Maximized 事件调用此方法。You cannot call this method from the Activated event when WindowState is set to Maximized.

注解

关闭窗体后,在该对象中创建的所有资源都将关闭并释放窗体。When a form is closed, all resources created within the object are closed and the form is disposed. 可以通过处理 Closing 事件并将作为参数传递的 CancelEventArgs 的 @no__t 属性设置为事件处理程序,来防止在运行时关闭窗体。You can prevent the closing of a form at run time by handling the Closing event and setting the Cancel property of the 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.

当窗体未在 @no__t 上释放时,两个条件为:(1)它是多文档界面(MDI)应用程序的一部分,并且窗体不可见;和(2)已使用 @no__t 显示窗体。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 ShowDialog. 在这些情况下,你将需要手动调用 Dispose 来标记窗体的所有控件以进行垃圾回收。In these cases, you will need to call Dispose manually to mark all of the form's controls for garbage collection.

备注

当在显示为无模式窗口的 @no__t 1 上调用 @no__t 的方法时,不能调用 Show 方法使窗体可见,因为窗体的资源已被释放。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. 若要隐藏窗体并使其可见,请使用 Control.Hide 方法。To hide a form and then make it visible, use the Control.Hide method.

注意

.NET Framework.NET Framework 2.0 之前,当调用 Application.Exit 方法退出应用程序时,不会引发 Form.Closed 和 @no__t 2 事件。Prior to the .NET Framework.NET Framework 2.0, the Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. 如果在必须执行的任何一个事件中都有验证代码,则应在调用 Exit 方法之前,分别为每个打开的窗体调用 Form.Close 方法。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.

适用于

另请参阅