共用方式為


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方法的方法的覆寫DoDefaultActionInitialize、在元件雙擊時顯示 的MessageBox覆蓋,以及屬性存取器的覆寫Verbs,該物件會提供元件快捷選單的自訂DesignerVerb選單指令。

#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 類別會修改屬性的預設值,使得預設值為物件實例化時的當前值。 這是因為該屬性是從另一個實例繼承而來的。 設計者定義重置屬性值即將其設為繼承類別所設定的值。 此值可能與元資料中預設值不同。

建構函式

名稱 Description
ComponentDesigner()

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

屬性

名稱 Description
ActionLists

取得與設計器相關元件所支援的設計時動作清單。

AssociatedComponents

取得設計師管理的與該元件相關的元件集合。

Component

取得設計師正在設計的元件。

InheritanceAttribute

會獲得一個屬性,表示相關元件繼承的類型。

Inherited

會得到一個值,表示該元件是否為繼承。

ParentComponent

取得這個設計器的父元件。

SetTextualDefaultProperty

延伸元件的設計模式行為。

ShadowProperties

會取得一組屬性值,覆蓋使用者設定。

Verbs

取得與設計者相關元件所支援的設計時動詞。

方法

名稱 Description
Dispose()

釋放所有由 ComponentDesigner.

Dispose(Boolean)

釋放 未管理的資源, ComponentDesigner 並可選擇性地釋放受管理資源。

DoDefaultAction()

在原始碼檔案中為元件的預設事件建立方法簽章,並引導使用者游標到該位置。

Equals(Object)

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

(繼承來源 Object)
Finalize()

嘗試在物件被垃圾回收前呼叫 Dispose(false) 來釋放資源。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetService(Type)

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

GetType()

取得目前實例的 Type

(繼承來源 Object)
Initialize(IComponent)

讓設計師準備好檢視、編輯並設計指定的元件。

InitializeExistingComponent(IDictionary)

重新初始化現有元件。

InitializeNewComponent(IDictionary)

初始化新建立的元件。

InitializeNonDefault()
已淘汰.
已淘汰.

初始化已初始化為非預設設定的匯入元件的設定。

InvokeGetInheritanceAttribute(ComponentDesigner)

得到 InheritanceAttribute 指定的 ComponentDesigner

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)

明確介面實作

名稱 Description
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 該物業。

適用於

另請參閱