Share via


Form.OnClosed 方法

引发 Closed 事件。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Protected Overridable Sub OnClosed ( _
    e As EventArgs _
)
用法
Dim e As EventArgs

Me.OnClosed(e)
protected virtual void OnClosed (
    EventArgs e
)
protected:
virtual void OnClosed (
    EventArgs^ e
)
protected void OnClosed (
    EventArgs e
)
protected function OnClosed (
    e : EventArgs
)

参数

备注

引发事件时会通过委托调用事件处理程序。有关更多信息,请参见 引发事件

OnClosed 方法还允许派生类对事件进行处理而不必附加委托。这是在派生类中处理事件的首选技术。

给实现者的说明 在派生类中重写 OnClosed 时,一定要调用基类的 OnClosed 方法,以便已注册的委托对事件进行接收。

示例

下面的代码示例演示如何重写从 Form 派生的类中的 OnClosed 方法。

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
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 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 extends Form
{
    protected void OnClosed(EventArgs e)
    {
        MessageBox.Show("The form is now closing.", "Close Warning", 
            MessageBoxButtons.OK, MessageBoxIcon.Warning);
        super.OnClosed(e);
    } //OnClosed

    public myForm()
    {
        super();
    } //myForm
} //myForm

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
Closed
EventArgs