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方法的方法的覆寫DoDefaultActionInitialize、在元件雙擊時顯示 的MessageBox覆蓋,以及屬性存取器的覆寫Verbs,該物件會提供元件快捷選單的自訂DesignerVerb選單指令。
#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 類別會修改屬性的預設值,使得預設值為物件實例化時的當前值。 這是因為該屬性是從另一個實例繼承而來的。 設計者定義重置屬性值即將其設為繼承類別所設定的值。 此值可能與元資料中預設值不同。
建構函式
| 名稱 | Description |
|---|---|
| ComponentDesigner() |
初始化 ComponentDesigner 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| ActionLists |
取得與設計器相關元件所支援的設計時動作清單。 |
| AssociatedComponents |
取得設計師管理的與該元件相關的元件集合。 |
| Component |
取得設計師正在設計的元件。 |
| InheritanceAttribute |
會獲得一個屬性,表示相關元件繼承的類型。 |
| Inherited |
會得到一個值,表示該元件是否為繼承。 |
| ParentComponent |
取得這個設計器的父元件。 |
| SetTextualDefaultProperty |
延伸元件的設計模式行為。 |
| ShadowProperties |
會取得一組屬性值,覆蓋使用者設定。 |
| Verbs |
取得與設計者相關元件所支援的設計時動詞。 |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| 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 該物業。 |