Form.OnClosed(EventArgs) Form.OnClosed(EventArgs) Form.OnClosed(EventArgs) Form.OnClosed(EventArgs) Method

定义

引发 Closed 事件。Raises the Closed event.

protected:
 virtual void OnClosed(EventArgs ^ e);
protected virtual void OnClosed (EventArgs e);
abstract member OnClosed : EventArgs -> unit
override this.OnClosed : EventArgs -> unit
Protected Overridable Sub OnClosed (e As EventArgs)

参数

e
EventArgs EventArgs EventArgs EventArgs

包含事件数据的 EventArgsThe EventArgs that contains the event data.

示例

下面的代码示例演示如何重写OnClosed方法在类中的派生自FormThe following code example demonstrates how to override the OnClosed method in a class derived from Form .

public ref class myForm: public Form
{
protected:
   virtual void OnClosed( EventArgs^ e ) override
   {
      MessageBox::Show( "The form is now closing.", "Close Warning", MessageBoxButtons::OK, MessageBoxIcon::Warning );
      Form::OnClosed( e );
   }

public:
   myForm()
      : Form()
   {}

};
public class myForm:
    Form

{
    protected override void OnClosed(EventArgs e)
    {
        MessageBox.Show("The form is now closing.", 
            "Close Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        base.OnClosed(e);
    }

    public myForm() : base()
    {        
    }

}

Public Class myForm
    Inherits Form

    Protected Overrides Sub OnClosed(ByVal e As EventArgs)
        MessageBox.Show("The form is now closing.", "Close Warning", _
            MessageBoxButtons.OK, MessageBoxIcon.Warning)
        MyBase.OnClosed(e)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

End Class

注解

注意

OnClosed方法已在.NET Framework 2.0 版中过时; 请使用OnFormClosed方法相反。The OnClosed method is obsolete in the .NET Framework version 2.0; use the OnFormClosed method instead.

引发事件时,将通过委托调用事件处理程序。Raising an event invokes the event handler through a delegate. 有关详细信息,请参阅处理和引发事件For more information, see Handling and Raising Events.

OnFormClosed 方法还允许派生类对事件进行处理而不必附加委托。The OnFormClosed method also allows derived classes to handle the event without attaching a delegate. 重写此方法是用于处理派生类中的事件的首选的技术。Overriding this method is the preferred technique for handling the event in a derived class.

注意

OnClosedOnClosing时,不调用方法Application.Exit方法调用以退出应用程序。The OnClosed and OnClosing methods are not called when the Application.Exit method is called to exit your application. 如果必须执行这些方法之一验证代码,应调用Form.Close单独之前,调用每个打开的窗体的方法Exit方法。If you have validation code in either of these methods that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.

继承者说明

在派生类中重写 OnClosed(EventArgs) 时,一定要调用基类的 OnClosed(EventArgs) 方法,以便已注册的委托对事件进行接收。When overriding OnClosed(EventArgs) in a derived class, be sure to call the base class's OnClosed(EventArgs) method so that registered delegates receive the event.

适用于

另请参阅