ComponentDesigner 類別

定義

擴充元件的設計模式行為。

public ref class ComponentDesigner : IDisposable, System::ComponentModel::Design::IDesigner, System::ComponentModel::Design::IDesignerFilter
public ref class ComponentDesigner : IDisposable, System::ComponentModel::Design::IComponentInitializer, System::ComponentModel::Design::IDesignerFilter, System::ComponentModel::Design::ITreeDesigner
public class ComponentDesigner : IDisposable, System.ComponentModel.Design.IDesigner, System.ComponentModel.Design.IDesignerFilter
public class ComponentDesigner : IDisposable, System.ComponentModel.Design.IComponentInitializer, System.ComponentModel.Design.IDesignerFilter, System.ComponentModel.Design.ITreeDesigner
type ComponentDesigner = class
    interface IDesigner
    interface IDisposable
    interface IDesignerFilter
type ComponentDesigner = class
    interface ITreeDesigner
    interface IDesigner
    interface IDisposable
    interface IDesignerFilter
    interface IComponentInitializer
Public Class ComponentDesigner
Implements IDesigner, IDesignerFilter, IDisposable
Public Class ComponentDesigner
Implements IComponentInitializer, IDesignerFilter, IDisposable, ITreeDesigner
繼承
ComponentDesigner
衍生
實作

範例

下列程式代碼範例提供與設計工具相關聯的範例 ComponentDesigner 實作和範例元件。 設計工具會實作呼叫基底方法的方法覆寫Initialize、按兩下元件時顯示 MessageBox 的方法覆DoDefaultAction寫,以及提供自定義DesignerVerb功能表命令給元件的快捷方式功能表的屬性存取子覆寫VerbsInitialize

#using <System.dll>
#using <System.Design.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;

// Provides an example component designer.
ref class ExampleComponentDesigner: public ComponentDesigner
{
public:
   ExampleComponentDesigner()
   {
   }

   // This method provides an opportunity to perform processing when a designer is initialized.
   // The component parameter is the component that the designer is associated with.
   virtual void Initialize( IComponent^ component ) override
   {
      // Always call the base Initialize method in an of this method.
      ComponentDesigner::Initialize( component );
   }

   // This method is invoked when the associated component is double-clicked.
   virtual void DoDefaultAction() override
   {
      MessageBox::Show( "The event handler for the default action was invoked." );
   }

   // This method provides designer verbs.
   property DesignerVerbCollection^ Verbs 
   {
      virtual DesignerVerbCollection^ get() override
      {
         array<DesignerVerb^>^ newDesignerVerbs = {gcnew DesignerVerb( "Example Designer Verb Command", gcnew EventHandler( this, &ExampleComponentDesigner::onVerb ) )};
         return gcnew DesignerVerbCollection( newDesignerVerbs );
      }
   }

private:
   // Event handling method for the example designer verb
   void onVerb( Object^ sender, EventArgs^ e )
   {
      MessageBox::Show( "The event handler for the Example Designer Verb Command was invoked." );
   }
};

// Provides an example component associated with the example component designer.

[DesignerAttribute(ExampleComponentDesigner::typeid, IDesigner::typeid)]
ref class ExampleComponent: public Component
{
public:
   ExampleComponent(){}
};
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace ExampleComponent
{	
    // Provides an example component designer.
    public class ExampleComponentDesigner : System.ComponentModel.Design.ComponentDesigner
    {
        public ExampleComponentDesigner()
        {
        }

        // This method provides an opportunity to perform processing when a designer is initialized.
        // The component parameter is the component that the designer is associated with.
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            // Always call the base Initialize method in an override of this method.
            base.Initialize(component);
        }

        // This method is invoked when the associated component is double-clicked.
        public override void DoDefaultAction()
        {
            MessageBox.Show("The event handler for the default action was invoked.");
        }

        // This method provides designer verbs.
        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Example Designer Verb Command", new EventHandler(this.onVerb)) } );
            }
        }

        // Event handling method for the example designer verb
        private void onVerb(object sender, EventArgs e)
        {
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.");
        }
    }

    // Provides an example component associated with the example component designer.
    [DesignerAttribute(typeof(ExampleComponentDesigner), typeof(IDesigner))]
    public class ExampleComponent : System.ComponentModel.Component
    {		
        public ExampleComponent()
        {
        }
    }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

Namespace ExampleComponent

    ' Provides an example component designer.
    Public Class ExampleComponentDesigner
        Inherits System.ComponentModel.Design.ComponentDesigner

        Public Sub New()
        End Sub

        ' This method provides an opportunity to perform processing when a designer is initialized.
        ' The component parameter is the component that the designer is associated with.
        Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
            ' Always call the base Initialize method in an override of this method.
            MyBase.Initialize(component)
        End Sub

        ' This method is invoked when the associated component is double-clicked.
        Public Overrides Sub DoDefaultAction()
            MessageBox.Show("The event handler for the default action was invoked.")
        End Sub

        ' This method provides designer verbs.
        Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
            Get
                Return New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("Example Designer Verb Command", New EventHandler(AddressOf Me.onVerb))})
            End Get
        End Property

        ' Event handling method for the example designer verb
        Private Sub onVerb(ByVal sender As Object, ByVal e As EventArgs)
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.")
        End Sub
    End Class

    ' Provides an example component associated with the example component designer.
    <DesignerAttribute(GetType(ExampleComponentDesigner), GetType(IDesigner))> _
     Public Class ExampleComponent
        Inherits System.ComponentModel.Component

        Public Sub New()
        End Sub
    End Class

End Namespace 'ExampleComponent

備註

ComponentDesigner 底設計工具類別提供簡單的設計工具,可在設計模式中擴充相關聯元件的行為。

ComponentDesigner 提供空 IDesignerFilter 的介面實作,可以覆寫其方法,以在設計時間調整相關聯元件的屬性、屬性和事件。

您可以使用 將設計工具與型 DesignerAttribute別產生關聯。 如需自定義設計時間行為的概觀,請參閱 擴充 Design-Time 支援

類別 ComponentDesigner 會實作繼承元件之屬性描述項的特殊行為。 默認ComponentDesigner實作會使用名為 InheritedPropertyDescriptor 的內部類型來代表繼承自基類的屬性。 有兩種情況會新增這些屬性描述項。

  1. 至屬性所傳回的 IDesignerHost.RootComponent 根物件本身,因為您繼承自其基類。

  2. 在根物件的基類中找到的欄位。 基類的公用和受保護字段會新增至設計工具,讓使用者可以操作它們。

類別 InheritedPropertyDescriptor 會修改屬性的預設值,讓預設值是物件具現化時的目前值。 這是因為 屬性繼承自另一個實例。 設計工具會定義重設 屬性值,將它設定為繼承類別所設定的值。 這個值可能與儲存在元數據中的預設值不同。

建構函式

ComponentDesigner()

初始化 ComponentDesigner 類別的新執行個體。

屬性

ActionLists

取得與設計工具相關之元件所支援的設計階段動作清單。

AssociatedComponents

取得元件集合,該集合與設計工具管理的元件相關聯。

Component

取得這個設計工具正在設計的元件。

InheritanceAttribute

取得屬性 (Attribute),表示相關元件的繼承 (Inheritance) 型別。

Inherited

取得值,表示是否要繼承這個元件。

ParentComponent

取得這個設計工具的父元件。

SetTextualDefaultProperty

擴充元件的設計模式行為。

ShadowProperties

取得覆寫使用者設定的屬性值集合。

Verbs

取得與設計工具相關元件所支援的設計階段動詞命令 (Verb)。

方法

Dispose()

釋放 ComponentDesigner 所使用的所有資源。

Dispose(Boolean)

釋放 ComponentDesigner 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

DoDefaultAction()

在元件上預設事件的原始程式碼檔案中建立方法簽章,並將使用者的游標巡覽至該位置。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

藉由在記憶體回收收回物件前呼叫 Dispose(false) 的方法,嘗試釋放資源。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetService(Type)

嘗試從設計工具元件的設計模式站台擷取指定的服務類型。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Initialize(IComponent)

準備設計工具,以檢視、編輯和設計所指定的元件。

InitializeExistingComponent(IDictionary)

重新初始化現有的元件。

InitializeNewComponent(IDictionary)

初始化新建立的元件。

InitializeNonDefault()
已淘汰.
已淘汰.

初始化已初始化為預設值以外設定的匯入元件設定。

InvokeGetInheritanceAttribute(ComponentDesigner)

取得指定 InheritanceAttributeComponentDesigner

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnSetComponentDefaults()
已淘汰.
已淘汰.

設定元件的預設屬性。

PostFilterAttributes(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。

PostFilterEvents(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的事件集中的項目。

PostFilterProperties(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。

PreFilterAttributes(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的屬性集。

PreFilterEvents(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的事件集。

PreFilterProperties(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的屬性集。

RaiseComponentChanged(MemberDescriptor, Object, Object)

告知 IComponentChangeService 這個元件已經變更。

RaiseComponentChanging(MemberDescriptor)

告知 IComponentChangeService 這個元件正要變更。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IDesignerFilter.PostFilterAttributes(IDictionary)

如需這個成員的描述,請參閱 PostFilterAttributes(IDictionary) 方法。

IDesignerFilter.PostFilterEvents(IDictionary)

如需這個成員的描述,請參閱 PostFilterEvents(IDictionary) 方法。

IDesignerFilter.PostFilterProperties(IDictionary)

如需這個成員的描述,請參閱 PostFilterProperties(IDictionary) 方法。

IDesignerFilter.PreFilterAttributes(IDictionary)

如需這個成員的描述,請參閱 PreFilterAttributes(IDictionary) 方法。

IDesignerFilter.PreFilterEvents(IDictionary)

如需這個成員的描述,請參閱 PreFilterEvents(IDictionary) 方法。

IDesignerFilter.PreFilterProperties(IDictionary)

如需這個成員的描述,請參閱 PreFilterProperties(IDictionary) 方法。

ITreeDesigner.Children

如需這個成員的描述,請參閱 Children 屬性。

ITreeDesigner.Parent

如需這個成員的描述,請參閱 Parent 屬性。

適用於

另請參閱