AxHost.SetAboutBoxDelegate(AxHost+AboutBoxDelegate) 方法

定义

调用 ShowAboutBox() 方法来显示 ActiveX 控件的“关于”对话框。Calls the ShowAboutBox() method to display the ActiveX control's About dialog box.

protected:
 void SetAboutBoxDelegate(System::Windows::Forms::AxHost::AboutBoxDelegate ^ d);
protected void SetAboutBoxDelegate (System.Windows.Forms.AxHost.AboutBoxDelegate d);
member this.SetAboutBoxDelegate : System.Windows.Forms.AxHost.AboutBoxDelegate -> unit
Protected Sub SetAboutBoxDelegate (d As AxHost.AboutBoxDelegate)

参数

示例

下面的代码示例将重写构造函数, SetAboutBoxDelegate以及AttachInterfaces包装 Microsoft 掩码AxHost编辑 ActiveX 控件的派生类的和方法。The following code example overrides the constructor, and the SetAboutBoxDelegate and AttachInterfaces methods of an AxHost derived class that wraps the Microsoft Masked Edit ActiveX Control. 此代码要求你已创建生成的源代码,方法是在 MSMask32 文件上运行 aximp.exe,并使用/source开关生成要编辑的包装类。This code requires that you have created the generated source code by running the AxImp.exe on the MSMask32.ocx file with the /source switch to generate the wrapper class to be edited. 此代码仅在语法中C#显示,因为这是 aximp.exe 所输出的唯一语言。This code is only shown in C# syntax because that is the only language output by the AxImp.exe.

public AxMaskEdBox()
    :
  base("c932ba85-4374-101b-a56c-00aa003668dc") // The ActiveX control's class identifier.
{
    // Make the AboutBox method the about box delegate.
    this.SetAboutBoxDelegate(new AboutBoxDelegate(AboutBox));
}

public virtual void AboutBox()
{
    // If the instance of the ActiveX control is null when the AboutBox method 
    // is called, raise an InvalidActiveXStateException exception.
    if ((this.ocx == null))
    {
        throw new System.Windows.Forms.AxHost.InvalidActiveXStateException(
          "AboutBox", System.Windows.Forms.AxHost.ActiveXInvokeKind.MethodInvoke);
    }
    // Show the about box if the ActiveX control has one.
    if (this.HasAboutBox)
    {
        this.ocx.AboutBox();
    }
}

protected override void AttachInterfaces()
{
    try
    {
        // Attach the IMSMask interface to the ActiveX control.
        this.ocx = ((MSMask.IMSMask)(this.GetOcx()));
    }
    catch (System.Exception ex)
    {
        System.Console.WriteLine(ex.Message);
    }
}

注解

方法还允许派生类ShowAboutBox处理方法而无需附加委托。 SetAboutBoxDelegateThe SetAboutBoxDelegate method also allows derived classes to handle the ShowAboutBox method without attaching a delegate. 这是在派生类中处理ShowAboutBox方法的首选方法。This is the preferred technique for handling the ShowAboutBox method in a derived class.

继承者说明

当在SetAboutBoxDelegate(AxHost+AboutBoxDelegate)派生类中重写时,请确保调用基类的SetAboutBoxDelegate(AxHost+AboutBoxDelegate)方法,以便注册ShowAboutBox()的委托接收方法。When overriding SetAboutBoxDelegate(AxHost+AboutBoxDelegate) in a derived class, be sure to call the base class's SetAboutBoxDelegate(AxHost+AboutBoxDelegate) method so that registered delegates receive the ShowAboutBox() method.

适用于

另请参阅