AxHost.GetOcx 方法

定义

检索对基础 ActiveX 控件的引用。Retrieves a reference to the underlying ActiveX control.

public:
 System::Object ^ GetOcx();
public object GetOcx ();
member this.GetOcx : unit -> obj
Public Function GetOcx () As Object

返回

表示 ActiveX 控件的对象。An object that represents the ActiveX control.

示例

下面的代码示例将重写构造函数, 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);
    }
}

适用于

另请参阅