다음을 통해 공유


AxHost 클래스

ActiveX 컨트롤을 래핑하여 완전한 기능의 Windows Forms 컨트롤로 노출시킵니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public MustInherit Class AxHost
    Inherits Control
    Implements ISupportInitialize, ICustomTypeDescriptor
‘사용 방법
Dim instance As AxHost
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public abstract class AxHost : Control, ISupportInitialize, ICustomTypeDescriptor
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class AxHost abstract : public Control, ISupportInitialize, ICustomTypeDescriptor
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public abstract class AxHost extends Control implements ISupportInitialize, ICustomTypeDescriptor
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public abstract class AxHost extends Control implements ISupportInitialize, ICustomTypeDescriptor

설명

대개 AxHost 클래스를 직접 사용하지는 않습니다. Windows Forms ActiveX 컨트롤 가져오기(Aximp.exe)를 사용하여 AxHost를 확장하는 래퍼를 생성할 수 있습니다.

ActiveX 컨트롤 가져오기는 AxHost 클래스에서 파생되는 클래스를 생성한 후 응용 프로그램에 대한 참조로 추가될 수 있는 라이브러리 파일(DLL)로 컴파일합니다. 또한 ActiveX 컨트롤 가져오기와 함께 /source 스위치를 사용할 수 있으며 AxHost 파생 클래스에 대해 C# 파일이 생성됩니다. 그런 다음 코드를 변경하고 라이브러리 파일로 다시 컴파일할 수 있습니다.

참고

ActiveX 컨트롤 멤버의 이름이 .NET Framework에 정의된 이름과 일치하면 ActiveX 컨트롤 가져오기는 AxHost 파생 클래스를 만들 때 멤버 이름 앞에 "Ctl"을 붙입니다. 예를 들어, ActiveX 컨트롤에 "Layout"이라는 멤버가 있으면 Layout 이벤트는 .NET Framework 내에서 정의되므로 해당 멤버 이름은 AxHost 파생 클래스에서 "CtlLayout"으로 다시 지정됩니다.

AxHost 클래스에서 대부분의 공통 속성은 내부 ActiveX 컨트롤이 해당 속성을 노출하는 경우에만 유효하여 사용될 수 있습니다. 이러한 공통 속성에는 BackColor, Cursor, FontText 등이 있습니다.

참고

Windows Forms 디자인 환경으로 Visual Studio .NET을 사용하는 경우 ActiveX 컨트롤을 도구 상자에 추가하면 응용 프로그램에서 해당 ActiveX 컨트롤을 사용할 수 있습니다. 이렇게 하려면 도구 상자를 마우스 오른쪽 단추로 클릭한 다음 도구 상자 사용자 지정을 선택하고 ActiveX 컨트롤의 .ocx 파일을 찾습니다. 자세한 내용은 Visual Basic.NET 설명서에서 "Adding ActiveX Controls to Windows Forms"를 참조하십시오.

예제

다음 코드 예제에서는 Microsoft Masked Edit ActiveX Control을 래핑하는 AxHost 파생 클래스의 SetAboutBoxDelegateAttachInterfaces 메서드와 생성자를 재정의합니다. 이 코드를 실행하려면 편집할 래퍼 클래스를 생성하기 위해 /source 스위치를 사용하여 MSMask32.ocx 파일에 대해 AxImp.exe를 실행함으로써 생성된 소스 코드를 만든 상태여야 합니다. 이 코드는 AxImp.exe에서 출력하는 유일한 언어인 C# 구문으로만 표시됩니다.

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);
    }
}

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.AxHost

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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 멤버
System.Windows.Forms 네임스페이스
Control
UserControl