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

获取一个特性,该特性指示关联组件的继承类型。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

获取与设计器相关联的组件所支持的设计时谓词。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 占用的非托管资源,还可以另外再释放托管资源。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 的浅表副本。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()

返回一个表示当前对象的 string。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.

适用于

另请参阅