英語で読む

次の方法で共有


IDesignerHost インターフェイス

定義

デザイナーのトランザクションおよびコンポーネントを管理するためのインターフェイスを提供します。

C#
public interface IDesignerHost : IServiceProvider, System.ComponentModel.Design.IServiceContainer
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface IDesignerHost : IServiceProvider, System.ComponentModel.Design.IServiceContainer
C#
public interface IDesignerHost : System.ComponentModel.Design.IServiceContainer
派生
属性
実装

次のコード例は、デザイナーまたはサイト コンポーネントからサービス インターフェイスを IDesignerHost 取得する方法を示しています。

C#
// Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
IDesignerHost dh = (IDesignerHost) this.Component.Site.GetService(typeof(IDesignerHost));

次のコード例では、 インターフェイスを IDesignerHost 使用してプロジェクト コンポーネントを一覧表示する方法を示します。

C#
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.
    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()
        {
            using (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 );
        }	
    }
}

注釈

IDesignerHostは、デザイナーのトランザクションとコンポーネント管理のサポートを提供するために、.NET Framework フォーム デザイナー アーキテクチャと連携するインターフェイスです。

.NET Frameworkでは、このインターフェイスの実装は提供されません。 インターフェイスは、デザイナーをサポートする開発ツールによって実装されます。

注意 (呼び出し元)

開発環境から の IDesignerHost 実装を取得するには、コンポーネントがデザイン モードでアクティブな間に を呼び出し GetService(Type) 、 の IDesignerHost 型を渡してサービス インターフェイスを IDesignerHost 要求します。

IDesignerHost には、デザイナーの状態に関連する次のメンバーが用意されています。

  • プロパティは Loading 、デザイナーまたはドキュメントが読み込まれているかどうかを示します。

  • このイベントは Activated 、デザイナーが表示前にアクティブになったときに発生します。

  • イベントは Deactivated 、デザイナーが非アクティブ化されるときに発生します。

  • イベントは LoadComplete 、ドキュメントが読み込まれた後に発生します。

  • メソッドは Activate() デザイナーをアクティブにします。

IDesignerHost には、コンポーネントの管理に関連する次のメンバーが用意されています。

  • プロパティは Container 、デザイナー ホストのコンテナーを示します。

  • プロパティは RootComponent 、ルート コンポーネントの基底クラスを示します。

  • プロパティは RootComponentClassName 、ルート コンポーネントのクラスの名前を示します。

  • メソッドは CreateComponent(Type) 、指定した種類のコンポーネントを作成します。

  • メソッドは DestroyComponent(IComponent) 、指定されたコンポーネントを破棄します。

  • メソッドは GetDesigner(IComponent) 、指定したコンポーネントに関連付けられているデザイナーを取得します。

  • メソッドは GetType(String) 、指定した名前の型のインスタンスを取得します。

IDesignerHost には、トランザクションの管理に関連する次のメンバーが用意されています。

  • プロパティは InTransaction 、デザイナーがトランザクション内にあるかどうかを示します。

  • プロパティは TransactionDescription 、現在のトランザクションの説明を示します。

  • イベントは TransactionClosed 、トランザクションが完了したときに発生します。

  • イベントは TransactionClosing 、トランザクションが完了しようとしているときに発生します。

  • イベントは TransactionOpened 、トランザクションが開始されたときに発生します。

  • イベントは TransactionOpening 、トランザクションが開始されようとしているときに発生します。

  • メソッドは CreateTransaction() 、新しいトランザクションを作成して返します。

プロパティ

Container

デザイナー ホストのコンテナーを取得します。

InTransaction

デザイナー ホストが現在トランザクションを実行中かどうかを示す値を取得します。

Loading

デザイナー ホストが現在ドキュメントを読み込み中かどうかを示す値を取得します。

RootComponent

現在のデザインのルート コンポーネントとして使用される、基本クラスのインスタンスを取得します。

RootComponentClassName

デザイン対象のクラスの完全限定名を取得します。

TransactionDescription

現在のトランザクションの説明を取得します。

メソッド

Activate()

ホストしているデザイナーをアクティブにします。

AddService(Type, Object)

指定されたサービスをサービス コンテナーに追加します。

(継承元 IServiceContainer)
AddService(Type, Object, Boolean)

指定されたサービスをサービス コンテナーに追加し、必要に応じてサービスを任意の親サービス コンテナーに昇格します。

(継承元 IServiceContainer)
AddService(Type, ServiceCreatorCallback)

指定されたサービスをサービス コンテナーに追加します。

(継承元 IServiceContainer)
AddService(Type, ServiceCreatorCallback, Boolean)

指定されたサービスをサービス コンテナーに追加し、必要に応じてサービスを親サービス コンテナーに昇格します。

(継承元 IServiceContainer)
CreateComponent(Type)

指定した型のコンポーネントを作成し、そのコンポーネントをデザイン ドキュメントに追加します。

CreateComponent(Type, String)

指定した型および名前のコンポーネントを作成し、そのコンポーネントをデザイン ドキュメントに追加します。

CreateTransaction()

一連のイベントをカプセル化することでパフォーマンスを向上させ、"元に戻す" 機能や "やり直し" 機能をサポートできるようにする DesignerTransaction を作成します。

CreateTransaction(String)

指定したトランザクションの説明を使用して、一連のイベントをカプセル化することでパフォーマンスを向上させ、"元に戻す" 機能や "やり直し" 機能をサポートできるようにする DesignerTransaction を作成します。

DestroyComponent(IComponent)

指定したコンポーネントを破棄し、デザイナー コンテナーからそのコンポーネントを削除します。

GetDesigner(IComponent)

指定したコンポーネントを格納しているデザイナー インスタンスを取得します。

GetService(Type)

指定した型のサービス オブジェクトを取得します。

(継承元 IServiceProvider)
GetType(String)

指定した完全限定型名のインスタンスを取得します。

RemoveService(Type)

指定されたサービスの型をサービス コンテナーから削除します。

(継承元 IServiceContainer)
RemoveService(Type, Boolean)

指定されたサービスの型をサービス コンテナーから削除し、必要に応じてサービスを親サービス コンテナーに昇格します。

(継承元 IServiceContainer)

イベント

Activated

デザイナーがアクティブになるときに発生します。

Deactivated

デザイナーがアクティブでなくなるときに発生します。

LoadComplete

デザイナーがドキュメントの読み込みを完了したときに発生します。

TransactionClosed

TransactionClosed イベントのイベント ハンドラーを追加します。

TransactionClosing

TransactionClosing イベントのイベント ハンドラーを追加します。

TransactionOpened

TransactionOpened イベントのイベント ハンドラーを追加します。

TransactionOpening

TransactionOpening イベントのイベント ハンドラーを追加します。

拡張メソッド

GetKeyedService<T>(IServiceProvider, Object)

から 型 T のサービスを取得します IServiceProvider

GetKeyedServices(IServiceProvider, Type, Object)

から 型 serviceType のサービスの列挙体を取得します IServiceProvider

GetKeyedServices<T>(IServiceProvider, Object)

から 型 T のサービスの列挙体を取得します IServiceProvider

GetRequiredKeyedService(IServiceProvider, Type, Object)

から 型 serviceType のサービスを取得します IServiceProvider

GetRequiredKeyedService<T>(IServiceProvider, Object)

から 型 T のサービスを取得します IServiceProvider

CreateAsyncScope(IServiceProvider)

スコープ サービスを解決するために使用できる新しい AsyncServiceScope を作成します。

CreateScope(IServiceProvider)

スコープ サービスを解決するために使用できる新しい IServiceScope を作成します。

GetRequiredService(IServiceProvider, Type)

IServiceProvider から serviceType 型のサービスを取得します。

GetRequiredService<T>(IServiceProvider)

IServiceProvider から T 型のサービスを取得します。

GetService<T>(IServiceProvider)

IServiceProvider から T 型のサービスを取得します。

GetServices(IServiceProvider, Type)

IServiceProvider から serviceType 型のサービスの列挙体を取得します。

GetServices<T>(IServiceProvider)

IServiceProvider から T 型のサービスの列挙体を取得します。

GetFakeLogCollector(IServiceProvider)

偽のロガーに送信されたログ レコードを収集する オブジェクトを取得します。

GetFakeRedactionCollector(IServiceProvider)

依存関係挿入コンテナーから偽の redactor コレクター インスタンスを取得します。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください