AxHost.AboutBoxDelegate 委托

定义

表示将显示 ActiveX 控件的“关于”对话框的方法。Represents the method that will display an ActiveX control's About dialog box.

protected: delegate void AxHost::AboutBoxDelegate();
protected delegate void AxHost.AboutBoxDelegate();
Protected Delegate Sub AxHost.AboutBoxDelegate()
继承
AxHost.AboutBoxDelegate

示例

下面的示例重写构造函数, 以及SetAboutBoxDelegate包装AttachInterfaces Microsoft 掩码编辑AxHost ActiveX 控件的派生类的和方法。The following 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 assumes 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 as 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);
    }
}

注解

AxHost.AboutBoxDelegate使您能够在 ActiveX 控件的 "关于" 框显示时收到通知。The AxHost.AboutBoxDelegate provides you the ability to be notified when the ActiveX control's About box is going to be displayed. 在显示 "关于" 框之前, 将执行添加到委托方法的代码。Code added to the delegate method is executed before the About box is displayed.

创建AxHost.AboutBoxDelegate委托时, 需要标识将处理 ActiveX 控件的 "关于" 对话框 (如果有) 的显示的方法。When you create an AxHost.AboutBoxDelegate delegate, you identify the method that will handle the display of an ActiveX control's About dialog box if it has one. 若要将方法与处理程序关联, 请将委托的实例添加到方法中。To associate the method with your handler, add an instance of the delegate to the method. 只要调用方法, 就会调用该处理程序, 除非删除委托。The handler is called whenever the method is called, unless you remove the delegate. 有关委托的详细信息, 请参阅处理和引发事件For more information about delegates, see Handling and Raising Events.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅