IDesignerHost 인터페이스
디자이너 트랜잭션과 구성 요소를 관리하기 위한 인터페이스를 제공합니다.
네임스페이스: System.ComponentModel.Design
어셈블리: System(system.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
Public Interface IDesignerHost
Inherits IServiceContainer, IServiceProvider
‘사용 방법
Dim instance As IDesignerHost
[ComVisibleAttribute(true)]
public interface IDesignerHost : IServiceContainer, IServiceProvider
[ComVisibleAttribute(true)]
public interface class IDesignerHost : IServiceContainer, IServiceProvider
/** @attribute ComVisibleAttribute(true) */
public interface IDesignerHost extends IServiceContainer, IServiceProvider
ComVisibleAttribute(true)
public interface IDesignerHost extends IServiceContainer, IServiceProvider
설명
IDesignerHost는 .NET Framework 폼 디자이너 아키텍처를 사용하여 디자이너 트랜잭션과 구성 요소 관리 지원을 제공하는 인터페이스입니다.
.NET Framework는 이 인터페이스를 구현하지 않습니다. 이 인터페이스는 디자이너를 지원하는 개발 도구에 의해 구현됩니다.
호출자 참고 사항 개발 환경에서 IDesignerHost를 구현하려면, 구성 요소가 디자인 모드에 활성화되어 있는 동안에 GetService를 호출하고 IDesignerHost의 형식을 전달하여 IDesignerHost 서비스 인터페이스를 요청합니다. IDesignerHost에서는 디자이너 상태와 관련된 다음 멤버를 제공합니다.
Loading 속성은 디자이너나 문서가 로드되고 있는지 여부를 나타냅니다.
Activated 이벤트는 디자이너가 표시되기 전에 활성화될 때 발생합니다.
Deactivated 이벤트는 디자이너가 비활성화될 때 발생합니다.
LoadComplete 이벤트는 문서가 로드된 후에 발생합니다.
Activate 메서드는 디자이너를 활성화합니다.
IDesignerHost에서는 구성 요소 관리와 관련된 다음 멤버를 제공합니다.
Container 속성은 디자이너 호스트에 대한 컨테이너를 나타냅니다.
RootComponent 속성은 루트 구성 요소에 대한 기본 클래스를 나타냅니다.
RootComponentClassName 속성은 루트 구성 요소의 클래스 이름을 나타냅니다.
CreateComponent 메서드는 지정된 형식의 구성 요소를 만듭니다.
DestroyComponent 메서드는 지정된 구성 요소를 소멸시킵니다.
GetDesigner 메서드는 지정된 구성 요소와 관련된 디자이너를 가져옵니다.
GetType 메서드는 지정된 이름 형식의 인스턴스를 가져옵니다.
IDesignerHost에서는 트랜잭션 관리와 관련된 다음 멤버를 제공합니다.
InTransaction 속성은 디자이너가 트랜잭션에 있는지 여부를 나타냅니다.
TransactionDescription 속성은 현재 트랜잭션 설명을 나타냅니다.
TransactionClosed 이벤트는 트랜잭션이 완료되었을 때 발생합니다.
TransactionClosing 이벤트는 트랜잭션이 완료되기 직전에 발생합니다.
TransactionOpened 이벤트는 트랜잭션이 시작되었을 때 발생합니다.
TransactionOpening 이벤트는 트랜잭션이 시작되기 직전에 발생합니다.
CreateTransaction 메서드는 새 트랜잭션을 만들어 반환합니다.
예제
다음 예제 코드에서는 디자이너나 사이트 정보를 포함하는 구성 요소에서 IDesignerHost 서비스 인터페이스를 얻는 방법을 보여 줍니다.
' Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
Dim host As IDesignerHost = CType(Me.Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
// Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
IDesignerHost dh = (IDesignerHost) this.Component.Site.GetService(typeof(IDesignerHost));
// Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
IDesignerHost^ dh = static_cast<IDesignerHost^>(this->Component->Site->GetService( IDesignerHost::typeid ));
// Requests an IDesignerHost service from the design time
// environment using Component.Site.GetService()
IDesignerHost dh = (IDesignerHost)this.get_Component().get_Site().
GetService(IDesignerHost.class.ToType());
다음 예제 코드에서는 IDesignerHost 인터페이스를 사용하여 프로젝트 구성 요소를 나열합니다.
Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms
Namespace IDesignerHostExample
' IDesignerHostExampleComponent is a component associated
' with the IDesignerHostExampleDesigner that demonstrates
' acquisition and use of the IDesignerHost service
' to list project components.
<DesignerAttribute(GetType(IDesignerHostExampleDesigner))> _
Public Class IDesignerHostExampleComponent
Inherits System.ComponentModel.Component
Public Sub New()
End Sub 'New
Protected Overloads Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
End Class
' You can double-click the component of a IDesignerHostExampleDesigner
' to show a form containing a listbox that lists the name and type
' of each component or control in the current design-time project.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class IDesignerHostExampleDesigner
Implements IDesigner
Private component_ As System.ComponentModel.IComponent
Public Sub New()
End Sub 'New
Public Sub DoDefaultAction() Implements IDesigner.DoDefaultAction
ListComponents()
End Sub
Public Sub Initialize(ByVal component As System.ComponentModel.IComponent) Implements IDesigner.Initialize
Me.component_ = component
MessageBox.Show("Double-click the IDesignerHostExample component to view a list of project components.")
End Sub
' Displays a list of components in the current design
' document when the default action of the designer is invoked.
Private Sub ListComponents()
Dim listform As New DesignerHostListForm()
' Obtain an IDesignerHost service from the design environment.
Dim host As IDesignerHost = CType(Me.component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
' Get the project components container (control containment depends on Controls collections)
Dim container As IContainer = host.Container
' Add each component's type name and name to the list box.
Dim comp As Component
For Each comp In container.Components
listform.listBox1.Items.Add((comp.GetType().Name + " : " + component.Site.Name))
Next comp
' Display the form.
listform.ShowDialog()
End Sub
Public ReadOnly Property Component() As System.ComponentModel.IComponent Implements IDesigner.Component
Get
Return component_
End Get
End Property
Public ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection Implements IDesigner.Verbs
Get
Dim dvc As New DesignerVerbCollection()
dvc.Add(New DesignerVerb("List Components", New EventHandler(AddressOf ListHandler)))
Return dvc
End Get
End Property
Private Sub ListHandler(ByVal sender As Object, ByVal e As EventArgs)
ListComponents()
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
End Class
_
' Provides a form containing a list box that can display
' a list of project components.
Public Class DesignerHostListForm
Inherits System.Windows.Forms.Form
Public listBox1 As System.Windows.Forms.ListBox
Private ok_button As System.Windows.Forms.Button
Public Sub New()
Me.Name = "DesignerHostListForm"
Me.Text = "List of design-time project components"
Me.SuspendLayout()
Me.listBox1 = New System.Windows.Forms.ListBox()
Me.listBox1.Location = New System.Drawing.Point(8, 8)
Me.listBox1.Name = "listBox1"
Me.listBox1.Size = New System.Drawing.Size(385, 238)
Me.listBox1.TabIndex = 0
Me.listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right)
Me.ok_button = New System.Windows.Forms.Button()
Me.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK
Me.ok_button.Location = New System.Drawing.Point(232, 256)
Me.ok_button.Name = "ok_button"
Me.ok_button.TabIndex = 1
Me.ok_button.Text = "OK"
Me.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
Me.ClientSize = New System.Drawing.Size(400, 285)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ok_button, Me.listBox1})
Me.ResumeLayout(False)
End Sub
Protected Overloads Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
End Class
End Namespace
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
namespace IDesignerHostExample
{
// IDesignerHostExampleComponent is a component associated
// with the IDesignerHostExampleDesigner that demonstrates
// acquisition and use of the IDesignerHost service
// to list project components.
[DesignerAttribute(typeof(IDesignerHostExampleDesigner))]
public class IDesignerHostExampleComponent : System.ComponentModel.Component
{
public IDesignerHostExampleComponent()
{}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
}
// You can double-click the component of an IDesignerHostExampleDesigner
// to show a form containing a listbox that lists the name and type
// of each component or control in the current design-time project.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class IDesignerHostExampleDesigner : IDesigner
{
private System.ComponentModel.IComponent component;
public IDesignerHostExampleDesigner()
{}
public void DoDefaultAction()
{
ListComponents();
}
public void Initialize(System.ComponentModel.IComponent component)
{
this.component = component;
MessageBox.Show("Double-click the IDesignerHostExample component to view a list of project components.");
}
// Displays a list of components in the current design
// document when the default action of the designer is invoked.
private void ListComponents()
{
DesignerHostListForm listform = new DesignerHostListForm();
// Obtain an IDesignerHost service from the design environment.
IDesignerHost host = (IDesignerHost)this.component.Site.GetService(typeof(IDesignerHost));
// Get the project components container (control containment depends on Controls collections)
IContainer container = host.Container;
// Add each component's type name and name to the list box.
foreach(IComponent component in container.Components)
{
listform.listBox1.Items.Add(component.GetType().Name + " : " + component.Site.Name);
}
// Display the form.
listform.ShowDialog();
}
public System.ComponentModel.IComponent Component
{
get
{
return this.component;
}
}
public System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection dvc = new DesignerVerbCollection();
dvc.Add( new DesignerVerb("List Components", new EventHandler(ListHandler)) );
return dvc;
}
}
private void ListHandler(object sender, EventArgs e)
{
ListComponents();
}
public void Dispose() { }
}
// Provides a form containing a listbox that can display
// a list of project components.
public class DesignerHostListForm : System.Windows.Forms.Form
{
public System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button ok_button;
public DesignerHostListForm()
{
this.Name = "DesignerHostListForm";
this.Text = "List of design-time project components";
this.SuspendLayout();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox1.Location = new System.Drawing.Point(8, 8);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(385, 238);
this.listBox1.TabIndex = 0;
this.listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.ok_button = new System.Windows.Forms.Button();
this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;
this.ok_button.Location = new System.Drawing.Point(232, 256);
this.ok_button.Name = "ok_button";
this.ok_button.TabIndex = 1;
this.ok_button.Text = "OK";
this.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.ClientSize = new System.Drawing.Size(400, 285);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.ok_button, this.listBox1 });
this.ResumeLayout(false);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
}
}
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;
// Provides a form containing a listbox that can display
// a list of project components.
public ref class DesignerHostListForm: public System::Windows::Forms::Form
{
public:
System::Windows::Forms::ListBox^ listBox1;
private:
System::Windows::Forms::Button^ ok_button;
public:
DesignerHostListForm()
{
this->Name = "DesignerHostListForm";
this->Text = "List of design-time project components";
this->SuspendLayout();
this->listBox1 = gcnew System::Windows::Forms::ListBox;
this->listBox1->Location = System::Drawing::Point( 8, 8 );
this->listBox1->Name = "listBox1";
this->listBox1->Size = System::Drawing::Size( 385, 238 );
this->listBox1->TabIndex = 0;
this->listBox1->Anchor = static_cast<AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) | System::Windows::Forms::AnchorStyles::Left) | System::Windows::Forms::AnchorStyles::Right);
this->ok_button = gcnew System::Windows::Forms::Button;
this->ok_button->DialogResult = System::Windows::Forms::DialogResult::OK;
this->ok_button->Location = System::Drawing::Point( 232, 256 );
this->ok_button->Name = "ok_button";
this->ok_button->TabIndex = 1;
this->ok_button->Text = "OK";
this->ok_button->Anchor = static_cast<AnchorStyles>(System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right);
this->ClientSize = System::Drawing::Size( 400, 285 );
array<System::Windows::Forms::Control^>^temp2 = {this->ok_button,this->listBox1};
this->Controls->AddRange( temp2 );
this->ResumeLayout( false );
}
public:
~DesignerHostListForm()
{
}
};
// You can double-click the component of an IDesignerHostExampleDesigner
// to show a form containing a listbox that lists the name and type
// of each component or control in the current design-time project.
public ref class IDesignerHostExampleDesigner: public IDesigner
{
private:
System::ComponentModel::IComponent^ component;
public:
IDesignerHostExampleDesigner(){}
virtual void DoDefaultAction()
{
ListComponents();
}
virtual void Initialize( System::ComponentModel::IComponent^ component )
{
this->component = component;
MessageBox::Show( "Double-click the IDesignerHostExample component to view a list of project components." );
}
private:
// Displays a list of components in the current design
// document when the default action of the designer is invoked.
void ListComponents()
{
DesignerHostListForm^ listform = gcnew DesignerHostListForm;
// Obtain an IDesignerHost service from the design environment.
IDesignerHost^ host = dynamic_cast<IDesignerHost^>(this->component->Site->GetService( IDesignerHost::typeid ));
// Get the project components container (control containment depends on Controls collections)
IContainer^ container = host->Container;
// Add each component's type name and name to the list box.
System::Collections::IEnumerator^ myEnum = container->Components->GetEnumerator();
while ( myEnum->MoveNext() )
{
IComponent^ component = safe_cast<IComponent^>(myEnum->Current);
listform->listBox1->Items->Add( String::Concat( component->GetType()->Name, " : ", component->Site->Name ) );
}
listform->ShowDialog();
}
public:
property System::ComponentModel::IComponent^ Component
{
virtual System::ComponentModel::IComponent^ get()
{
return this->component;
}
}
property System::ComponentModel::Design::DesignerVerbCollection^ Verbs
{
[PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
virtual System::ComponentModel::Design::DesignerVerbCollection^ get()
{
DesignerVerbCollection^ dvc = gcnew DesignerVerbCollection;
dvc->Add( gcnew DesignerVerb( "List Components",gcnew EventHandler( this, &IDesignerHostExampleDesigner::ListHandler ) ) );
return dvc;
}
}
private:
void ListHandler( Object^ /*sender*/, EventArgs^ /*e*/ )
{
ListComponents();
}
public:
~IDesignerHostExampleDesigner(){}
};
// IDesignerHostExampleComponent is a component associated
// with the IDesignerHostExampleDesigner that demonstrates
// acquisition and use of the IDesignerHost service
// to list project components.
[DesignerAttribute(IDesignerHostExampleDesigner::typeid)]
public ref class IDesignerHostExampleComponent: public System::ComponentModel::Component
{
public:
IDesignerHostExampleComponent(){}
public:
~IDesignerHostExampleComponent(){}
};
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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에서 지원
참고 항목
참조
IDesignerHost 멤버
System.ComponentModel.Design 네임스페이스
IDesigner 인터페이스
IDesignerEventService 인터페이스
IDesignerOptionService