ComponentDesigner 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
扩展组件的设计模式行为。
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菜单命令的属性访问器的替代Verbs。Initialize
#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
的内部类型来代表从基类继承的属性。 在两种情况下,添加这些属性描述符。
到根对象本身(由 IDesignerHost.RootComponent 属性返回),因为你是从其基类继承的。
在根对象的基类中找到的字段。 基类中的公共字段和受保护字段将添加到设计器中,以便用户可对其进行操作。
类 InheritedPropertyDescriptor
修改属性的默认值,以便默认值是对象实例化的当前值。 这是因为属性继承自另一个实例。 设计器将重置属性值定义为将其设置为由继承类设置的值。 此值可能与存储在元数据中的默认值不同。
构造函数
ComponentDesigner() |
初始化 ComponentDesigner 类的新实例。 |
属性
ActionLists |
获取与设计器相关联的组件所支持的设计时操作列表。 |
AssociatedComponents |
获取与设计器所管理的组件关联的组件集合。 |
Component |
获取此设计器正在设计的组件。 |
InheritanceAttribute |
获取一个特性,该特性指示关联组件的继承类型。 |
Inherited |
获取一个值,该值指示是否继承此组件。 |
ParentComponent |
获取此设计器的父组件。 |
SetTextualDefaultProperty |
扩展组件的设计模式行为。 |
ShadowProperties |
获取重写用户设置的属性值的集合。 |
Verbs |
获取与设计器相关联的组件所支持的设计时谓词。 |
方法
显式接口实现
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 属性。 |