ComponentDesigner 类
扩展组件的设计模式行为。
**命名空间:**System.ComponentModel.Design
**程序集:**System.Design(在 system.design.dll 中)
语法
声明
Public Class ComponentDesigner
Implements ITreeDesigner, IDesigner, IDisposable, IDesignerFilter, _
IComponentInitializer
用法
Dim instance As ComponentDesigner
public class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable,
IDesignerFilter, IComponentInitializer
public ref class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable,
IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner,
IDisposable, IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner,
IDisposable, IDesignerFilter, IComponentInitializer
备注
ComponentDesigner 基设计器类提供一种简单的设计器,该设计器可在设计模式下扩展关联组件的行为。
ComponentDesigner 提供空的 IDesignerFilter 接口实现,可以重写该实现的方法,从而在设计时调整关联组件的属性 (Attribute)、属性 (Property) 和事件。
可以使用 DesignerAttribute 将设计器与类型关联起来。有关自定义设计时行为的概述,请参见 扩展设计时支持。
示例
下面的代码示例提供 ComponentDesigner 实现示例和与该设计器关联的组件示例。该设计器实现 Initialize 方法的重写,该方法调用基本 Initialize 方法;实现 DoDefaultAction 方法的重写,该方法在组件被双击时显示 MessageBox;实现 Verbs 属性访问器的重写,该访问器向组件的快捷菜单提供自定义的 DesignerVerb 菜单命令。
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
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()
{
}
}
}
#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(){}
};
package ExampleComponent;
import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Windows.Forms.*;
// Provides an example component designer.
public class ExampleComponentDesigner
extends System.ComponentModel.Design.ComponentDesigner
{
public ExampleComponentDesigner()
{
} //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 void Initialize(System.ComponentModel.IComponent component)
{
// Always call the base Initialize method in an override of this method.
super.Initialize(component);
} //Initialize
// This method is invoked when the associated component is double-clicked.
public void DoDefaultAction()
{
MessageBox.Show("The event handler for the default action was invoked.");
} //DoDefaultAction
// This method provides designer verbs.
/** @property
*/
public System.ComponentModel.Design.DesignerVerbCollection get_Verbs()
{
return new DesignerVerbCollection(new DesignerVerb[]
{ new DesignerVerb("Example Designer Verb Command",
new EventHandler(this.OnVerb)) });
} //get_Verbs
// 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.");
} //OnVerb
} //ExampleComponentDesigner
// Provides an example component associated with the example component designer.
/** @attribute DesignerAttribute(ExampleComponentDesigner.class, IDesigner.class)
*/
public class ExampleComponent extends System.ComponentModel.Component
{
public ExampleComponent()
{
} //ExampleComponent
} //ExampleComponent
继承层次结构
System.Object
System.ComponentModel.Design.ComponentDesigner
派生类
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
ComponentDesigner 成员
System.ComponentModel.Design 命名空间
IDesigner
IDesignerFilter
DesignerAttribute 类