AxHost.AttachInterfaces 方法

当在派生类中重写时,将界面附加至基础 ActiveX 控件。

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

语法

声明
Protected Overridable Sub AttachInterfaces
用法

Me.AttachInterfaces
protected virtual void AttachInterfaces ()
protected:
virtual void AttachInterfaces ()
protected void AttachInterfaces ()
protected function AttachInterfaces ()

备注

给继承者的说明 扩展 AxHost 的类应重写此方法。在此方法的重写版本中,扩展类应调用 GetOcx 来检索其他自己的界面。在大多数情况下,不应在调用此方法之前调用 GetOcx 方法。

示例

下面的代码示例重写此构造函数,并重写包装 Microsoft Masked Edit ActiveX 控件的 AxHost 派生类的 SetAboutBoxDelegateAttachInterfaces 方法。此代码要求您已经通过使用 /source 开关对 MSMask32.ocx 文件运行 AxImp.exe 而生成了要编辑的包装类,从而创建了生成的源代码。此代码仅用 C# 语法显示,因为那是 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);
    }
}

平台

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

请参见

参考

AxHost 类
AxHost 成员
System.Windows.Forms 命名空间
GetOcx