ComponentDesigner ComponentDesigner ComponentDesigner ComponentDesigner Class

定義

擴充元件的設計模式行為。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
繼承
ComponentDesignerComponentDesignerComponentDesignerComponentDesigner
衍生
實作

範例

下列程式碼範例提供範例ComponentDesigner實作與設計工具相關聯的範例元件。The following code example provides an example ComponentDesigner implementation and an example component associated with the designer. 設計工具會實作覆寫Initialize方法來呼叫基底Initialize方法,覆寫DoDefaultAction方法,以顯示MessageBox按兩下元件時,並覆寫的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
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 'New

        ' 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 'Initialize

        ' 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 'DoDefaultAction

        ' 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 'onVerb
    End Class 'ExampleComponentDesigner

    ' 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 'New
    End Class 'ExampleComponent

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.

您可以將設計工具與型別,使用DesignerAttributeYou 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. 名為內部型別InheritedPropertyDescriptor預設會使用ComponentDesigner實作,以代表繼承自基底類別的屬性。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 和 protected 欄位都會加入至設計工具中,以便它們可以由使用者操作。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() ComponentDesigner() ComponentDesigner()

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

屬性

ActionLists ActionLists ActionLists ActionLists

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

AssociatedComponents AssociatedComponents AssociatedComponents AssociatedComponents

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

Component Component Component Component

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

InheritanceAttribute InheritanceAttribute InheritanceAttribute InheritanceAttribute

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

Inherited Inherited Inherited Inherited

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

ParentComponent ParentComponent ParentComponent ParentComponent

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

ShadowProperties ShadowProperties ShadowProperties ShadowProperties

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

Verbs Verbs Verbs Verbs

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

方法

Dispose() Dispose() Dispose() Dispose()

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

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

DoDefaultAction() DoDefaultAction() DoDefaultAction() 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) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

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

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
Initialize(IComponent) Initialize(IComponent) Initialize(IComponent) Initialize(IComponent)

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

InitializeExistingComponent(IDictionary) InitializeExistingComponent(IDictionary) InitializeExistingComponent(IDictionary) InitializeExistingComponent(IDictionary)

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

InitializeNewComponent(IDictionary) InitializeNewComponent(IDictionary) InitializeNewComponent(IDictionary) InitializeNewComponent(IDictionary)

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

InitializeNonDefault() InitializeNonDefault() InitializeNonDefault() InitializeNonDefault()

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

InvokeGetInheritanceAttribute(ComponentDesigner) InvokeGetInheritanceAttribute(ComponentDesigner) InvokeGetInheritanceAttribute(ComponentDesigner) InvokeGetInheritanceAttribute(ComponentDesigner)

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
OnSetComponentDefaults() OnSetComponentDefaults() OnSetComponentDefaults() OnSetComponentDefaults()

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

PostFilterAttributes(IDictionary) PostFilterAttributes(IDictionary) PostFilterAttributes(IDictionary) PostFilterAttributes(IDictionary)

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

PostFilterEvents(IDictionary) PostFilterEvents(IDictionary) PostFilterEvents(IDictionary) PostFilterEvents(IDictionary)

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

PostFilterProperties(IDictionary) PostFilterProperties(IDictionary) PostFilterProperties(IDictionary) PostFilterProperties(IDictionary)

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

PreFilterAttributes(IDictionary) PreFilterAttributes(IDictionary) PreFilterAttributes(IDictionary) PreFilterAttributes(IDictionary)

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

PreFilterEvents(IDictionary) PreFilterEvents(IDictionary) PreFilterEvents(IDictionary) PreFilterEvents(IDictionary)

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

PreFilterProperties(IDictionary) PreFilterProperties(IDictionary) PreFilterProperties(IDictionary) PreFilterProperties(IDictionary)

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

RaiseComponentChanged(MemberDescriptor, Object, Object) RaiseComponentChanged(MemberDescriptor, Object, Object) RaiseComponentChanged(MemberDescriptor, Object, Object) RaiseComponentChanged(MemberDescriptor, Object, Object)

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

RaiseComponentChanging(MemberDescriptor) RaiseComponentChanging(MemberDescriptor) RaiseComponentChanging(MemberDescriptor) RaiseComponentChanging(MemberDescriptor)

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

ToString() ToString() ToString() ToString()

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

(Inherited from Object)

明確介面實作

IDesignerFilter.PostFilterAttributes(IDictionary) IDesignerFilter.PostFilterAttributes(IDictionary) IDesignerFilter.PostFilterAttributes(IDictionary) IDesignerFilter.PostFilterAttributes(IDictionary)

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

IDesignerFilter.PostFilterEvents(IDictionary) IDesignerFilter.PostFilterEvents(IDictionary) IDesignerFilter.PostFilterEvents(IDictionary) IDesignerFilter.PostFilterEvents(IDictionary)

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

IDesignerFilter.PostFilterProperties(IDictionary) IDesignerFilter.PostFilterProperties(IDictionary) IDesignerFilter.PostFilterProperties(IDictionary) IDesignerFilter.PostFilterProperties(IDictionary)

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

IDesignerFilter.PreFilterAttributes(IDictionary) IDesignerFilter.PreFilterAttributes(IDictionary) IDesignerFilter.PreFilterAttributes(IDictionary) IDesignerFilter.PreFilterAttributes(IDictionary)

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

IDesignerFilter.PreFilterEvents(IDictionary) IDesignerFilter.PreFilterEvents(IDictionary) IDesignerFilter.PreFilterEvents(IDictionary) IDesignerFilter.PreFilterEvents(IDictionary)

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

IDesignerFilter.PreFilterProperties(IDictionary) IDesignerFilter.PreFilterProperties(IDictionary) IDesignerFilter.PreFilterProperties(IDictionary) IDesignerFilter.PreFilterProperties(IDictionary)

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

ITreeDesigner.Children ITreeDesigner.Children ITreeDesigner.Children ITreeDesigner.Children

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

ITreeDesigner.Parent ITreeDesigner.Parent ITreeDesigner.Parent ITreeDesigner.Parent

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

適用於

另請參閱