英語で読む

次の方法で共有


IDesigner インターフェイス

定義

カスタム デザイナーを構築するための基本フレームワークを提供します。

C#
public interface IDesigner : IDisposable
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface IDesigner : IDisposable
派生
属性
実装

この例では、コンポーネントへのローカル参照を格納し、コンポーネントがダブルクリックされたときに既定のアクションを実行し、デザイナー動詞メニュー コマンドを提供する実装を示 IDesigner します。

C#
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace IDesignerExample
{	
    // A DesignerAttribute associates the example IDesigner with an example control.
    [DesignerAttribute(typeof(ExampleIDesigner))]
    public class TestControl : System.Windows.Forms.UserControl
    {				
        public TestControl()
        {	
        }
    }

    public class ExampleIDesigner : System.ComponentModel.Design.IDesigner
    {
        // Local reference to the designer's component.
        private IComponent component; 
        // Public accessor to the designer's component.
        public System.ComponentModel.IComponent Component
        {
            get
            {
                return component;
            }            
        }

        public ExampleIDesigner()
        {            
        }

        public void Initialize(System.ComponentModel.IComponent component)
        {
            // This method is called after a designer for a component is created,
            // and stores a reference to the designer's component.
            this.component = component;
        }        
        
        // This method peforms the 'default' action for the designer. The default action 
        // for a basic IDesigner implementation is invoked when the designer's component 
        // is double-clicked. By default, a component associated with a basic IDesigner 
        // implementation is displayed in the design-mode component tray.
        public void DoDefaultAction()
        {
            // Shows a message box indicating that the default action for the designer was invoked.
            MessageBox.Show("The DoDefaultAction method of an IDesigner implementation was invoked.", "Information");
        }

        // Returns a collection of designer verb menu items to show in the 
        // shortcut menu for the designer's component.
        public System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                DesignerVerbCollection verbs = new DesignerVerbCollection();
                DesignerVerb dv1 = new DesignerVerb("Display Component Name", new EventHandler(this.ShowComponentName));
                verbs.Add( dv1 );
                return verbs;
            }
        }

        // Event handler for displaying a message box showing the designer's component's name.
        private void ShowComponentName(object sender, EventArgs e)
        {
            if( this.Component != null )
                MessageBox.Show( this.Component.Site.Name, "Designer Component's Name" );
        }

        // Provides an opportunity to release resources before object destruction.
        public void Dispose()
        {        
        }
    }
}

注釈

インターフェイスには IDesigner 、デザイナーの基本的なサービスを実装するためのインターフェイスが用意されています。 デザイナーは、デザイン時にコンポーネントの動作を変更でき、独自のサービスと動作を提供できます。 デザイナーはデザイン時にのみアクティブであり、関連付けられた型のコンポーネントがデザイン時に作成されるときに読み込まれるには、 を使用して DesignerAttribute コンポーネントの種類に関連付ける必要があります。

インターフェイスには IDesigner 、デザイン時にカスタム動作を提供するために実装できるメソッドとプロパティが用意されています。

コンポーネントの作成時に Initialize アクションを実行するデザイナーの メソッドを実装します。 これは、デザイン時にコンポーネントに特別な構成が必要な場合や、デザイナーが判断できる条件に応じて構成を変更する必要がある場合に便利です。

デザイナーは、ユーザーがデザイン時環境でコンポーネントまたはコントロールを右クリックしたときに表示されるショートカット メニューにメニュー コマンドを提供できます。 プロパティをVerbs実装して、メニュー コマンドを生成するための オブジェクトを含む DesignerVerbDesignerVerbCollection返す get アクセサーを定義できます。

コンポーネント トレイに表示されるコンポーネントのデザイナーは、コンポーネントがダブルクリックされたときに既定のアクションを実行できます。 コンポーネントが DoDefaultAction ダブルクリックされたときに実行する動作を指定する メソッドを実装します。

デザイナーは、使用可能なデザイン時サービスを使用して、コンポーネントとそのプロパティの現在のデザイン時環境の調査、コンポーネントのプロパティの値の読み取りと設定、ツールボックスの管理、選択したコンポーネントの管理、値の構成や処理の適用に使用できるユーザー インターフェイスの表示など、さまざまなタスクを実行することもできます。

フォームに配置できるコントロールのデザイナーを実装するには、 クラスから ControlDesigner 継承できます。 関連付けられたデザイナーが から ControlDesigner 派生していないコントロールは、コンポーネント トレイに表示されます。 クラスと ControlDesigner クラスは ComponentDesigner インターフェイスをIDesigner実装し、デザイナーの作成者に使用できる追加のデザイン時サポートを提供します。 詳細については、これらのクラスのリファレンス ドキュメントを参照してください。

設計コンポーネントの作成の概要については、「 Design-Time サポートの拡張」を参照してください。

プロパティ

Component

デザイナーがデザインする基本コンポーネントを取得します。

Verbs

デザイナーでサポートされているデザイン時動詞のコレクションを取得します。

メソッド

Dispose()

アンマネージ リソースの解放またはリセットに関連付けられているアプリケーション定義のタスクを実行します。

(継承元 IDisposable)
DoDefaultAction()

デザイナーの既定のアクションを実行します。

Initialize(IComponent)

コンポーネントを指定して、デザイナーを初期化します。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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

こちらもご覧ください