ComponentDesigner 類別

定義

擴充元件的設計模式行為。Extends the design mode behavior of a component.

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

範例

下列程式碼範例提供範例 ComponentDesigner 的執行,以及與設計工具相關聯的範例元件。The following code example provides an example ComponentDesigner implementation and an example component associated with the designer. 設計工具會執行 Initialize 方法的覆寫,以呼叫基底 Initialize 方法、在按兩下該元件時顯示 MessageBoxDoDefaultAction 方法的覆寫,以及提供的 Verbs 屬性存取子的覆寫。自訂 DesignerVerb 功能表命令至元件的快捷方式功能表。The designer implements an override of the Initialize method that calls the base Initialize method, an override of the DoDefaultAction method that displays a MessageBox when the component is double-clicked, and an override of the Verbs property accessor that supplies a custom DesignerVerb menu command to the shortcut menu for the component.

#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 基底設計工具類別提供簡單的設計工具,可在設計模式中擴充相關元件的行為。The ComponentDesigner base designer class provides a simple designer that can extend the behavior of an associated component in design mode.

ComponentDesigner 提供空的 IDesignerFilter 介面實作為,其方法可以覆寫,以便在設計階段調整關聯元件的屬性、屬性和事件。ComponentDesigner provides an empty IDesignerFilter interface implementation, whose methods can be overridden to adjust the attributes, properties and events of the associated component at design time.

您可以使用 DesignerAttribute,將設計工具與型別產生關聯。You can associate a designer with a type using a DesignerAttribute. 如需自訂設計階段行為的總覽,請參閱擴充設計階段支援For an overview of customizing design-time behavior, see Extending Design-Time Support.

ComponentDesigner 類別會針對繼承元件的屬性描述元執行特殊行為。The ComponentDesigner class implements a special behavior for the property descriptors of inherited components. 預設的 ComponentDesigner 執行會使用名為 InheritedPropertyDescriptor 的內部型別,來針對繼承自基類的屬性進行替代。An internal type named InheritedPropertyDescriptor is used by the default ComponentDesigner implementation to stand in for properties that are inherited from a base class. 在兩種情況下,會加入這些屬性描述項。There are two cases in which these property descriptors are added.

  1. 至根物件本身,由 IDesignerHost.RootComponent 屬性傳回,因為您是從其基類繼承而來。To the root object itself, which is returned by the IDesignerHost.RootComponent property, because you are inheriting from its base class.

  2. 在根物件的基類中找到的欄位。To fields found in the base class of the root object. 基類中的公用和受保護欄位會加入至設計工具,讓使用者可以操作它們。Public and protected fields from the base class are added to the designer so that they can be manipulated by the user.

InheritedPropertyDescriptor 類別會修改屬性的預設值,因此預設值是在物件具現化時的目前值。The InheritedPropertyDescriptor class modifies the default value of a property, so that the default value is the current value at object instantiation. 這是因為屬性繼承自另一個實例。This is because the property is inherited from another instance. 設計工具會定義將屬性值設定為繼承類別所設定的值,以進行重設。The designer defines resetting the property value as setting it to the value that was set by the inherited class. 這個值可能會與儲存在中繼資料中的預設值不同。This value may differ from the default value stored in metadata.

建構函式

ComponentDesigner()

初始化 ComponentDesigner 類別的新執行個體。Initializes a new instance of the ComponentDesigner class.

屬性

ActionLists

取得與設計工具相關之元件所支援的設計階段動作清單。Gets the design-time action lists supported by the component associated with the designer.

AssociatedComponents

取得元件集合,該集合與設計工具管理的元件相關聯。Gets the collection of components associated with the component managed by the designer.

Component

取得這個設計工具正在設計的元件。Gets the component this designer is designing.

InheritanceAttribute

取得屬性 (Attribute),表示相關元件的繼承 (Inheritance) 型別。Gets an attribute that indicates the type of inheritance of the associated component.

Inherited

取得值,表示是否要繼承這個元件。Gets a value indicating whether this component is inherited.

ParentComponent

取得這個設計工具的父元件。Gets the parent component for this designer.

ShadowProperties

取得覆寫使用者設定的屬性值集合。Gets a collection of property values that override user settings.

Verbs

取得與設計工具相關元件所支援的設計階段動詞命令 (Verb)。Gets the design-time verbs supported by the component that is associated with the designer.

方法

Dispose()

釋放 ComponentDesigner 所使用的所有資源。Releases all resources used by the ComponentDesigner.

Dispose(Boolean)

釋放 ComponentDesigner 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the ComponentDesigner and optionally releases the managed resources.

DoDefaultAction()

在元件上預設事件的原始程式碼檔案中建立方法簽章,並將使用者的游標巡覽至該位置。Creates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Finalize()

藉由在記憶體回收收回物件前呼叫 Dispose(false) 的方法,嘗試釋放資源。Attempts to free resources by calling Dispose(false) before the object is reclaimed by garbage collection.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetService(Type)

嘗試從設計工具元件的設計模式站台擷取指定的服務類型。Attempts to retrieve the specified type of service from the design mode site of the designer's component.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
Initialize(IComponent)

準備設計工具,以檢視、編輯和設計所指定的元件。Prepares the designer to view, edit, and design the specified component.

InitializeExistingComponent(IDictionary)

重新初始化現有的元件。Reinitializes an existing component.

InitializeNewComponent(IDictionary)

初始化新建立的元件。Initializes a newly created component.

InitializeNonDefault()

初始化已初始化為預設值以外設定的匯入元件設定。Initializes the settings for an imported component that is already initialized to settings other than the defaults.

InvokeGetInheritanceAttribute(ComponentDesigner)

取得指定 InheritanceAttributeComponentDesignerGets the InheritanceAttribute of the specified ComponentDesigner.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnSetComponentDefaults()

設定元件的預設屬性。Sets the default properties for the component.

PostFilterAttributes(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。Allows a designer to change or remove items from the set of attributes that it exposes through a TypeDescriptor.

PostFilterEvents(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的事件集中的項目。Allows a designer to change or remove items from the set of events that it exposes through a TypeDescriptor.

PostFilterProperties(IDictionary)

允許設計工具變更或移除它經由 TypeDescriptor 公開的屬性集中的項目。Allows a designer to change or remove items from the set of properties that it exposes through a TypeDescriptor.

PreFilterAttributes(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的屬性集。Allows a designer to add to the set of attributes that it exposes through a TypeDescriptor.

PreFilterEvents(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的事件集。Allows a designer to add to the set of events that it exposes through a TypeDescriptor.

PreFilterProperties(IDictionary)

允許設計工具加入至它經由 TypeDescriptor 公開的屬性集。Allows a designer to add to the set of properties that it exposes through a TypeDescriptor.

RaiseComponentChanged(MemberDescriptor, Object, Object)

告知 IComponentChangeService 這個元件已經變更。Notifies the IComponentChangeService that this component has been changed.

RaiseComponentChanging(MemberDescriptor)

告知 IComponentChangeService 這個元件正要變更。Notifies the IComponentChangeService that this component is about to be changed.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

IDesignerFilter.PostFilterAttributes(IDictionary)

如需這個成員的描述,請參閱 PostFilterAttributes(IDictionary) 方法。For a description of this member, see the PostFilterAttributes(IDictionary) method.

IDesignerFilter.PostFilterEvents(IDictionary)

如需這個成員的描述,請參閱 PostFilterEvents(IDictionary) 方法。For a description of this member, see the PostFilterEvents(IDictionary) method.

IDesignerFilter.PostFilterProperties(IDictionary)

如需這個成員的描述,請參閱 PostFilterProperties(IDictionary) 方法。For a description of this member, see the PostFilterProperties(IDictionary) method.

IDesignerFilter.PreFilterAttributes(IDictionary)

如需這個成員的描述,請參閱 PreFilterAttributes(IDictionary) 方法。For a description of this member, see the PreFilterAttributes(IDictionary) method.

IDesignerFilter.PreFilterEvents(IDictionary)

如需這個成員的描述,請參閱 PreFilterEvents(IDictionary) 方法。For a description of this member, see the PreFilterEvents(IDictionary) method.

IDesignerFilter.PreFilterProperties(IDictionary)

如需這個成員的描述,請參閱 PreFilterProperties(IDictionary) 方法。For a description of this member, see the PreFilterProperties(IDictionary) method.

ITreeDesigner.Children

如需這個成員的描述,請參閱 Children 屬性。For a description of this member, see the Children property.

ITreeDesigner.Parent

如需這個成員的描述,請參閱 Parent 屬性。For a description of this member, see the Parent property.

適用於

另請參閱