DesignerActionPropertyItem 類別

定義

代表與從 DesignerActionList 衍生之類別中屬性相關聯的面板項目。 此類別無法獲得繼承。

public ref class DesignerActionPropertyItem sealed : System::ComponentModel::Design::DesignerActionItem
public sealed class DesignerActionPropertyItem : System.ComponentModel.Design.DesignerActionItem
type DesignerActionPropertyItem = class
    inherit DesignerActionItem
Public NotInheritable Class DesignerActionPropertyItem
Inherits DesignerActionItem
繼承
DesignerActionPropertyItem

範例

下列程式代碼範例示範如何建立 物件的集合 DesignerActionItem 。 如需實作智慧標記的完整範例,請參閱如何:將智慧標記附加至 Windows Forms元件

public override DesignerActionItemCollection GetSortedActionItems()
{
    DesignerActionItemCollection items = new DesignerActionItemCollection();

    //Define static section header entries.
    items.Add(new DesignerActionHeaderItem("Appearance"));
    items.Add(new DesignerActionHeaderItem("Information"));

    //Boolean property for locking color selections.
    items.Add(new DesignerActionPropertyItem("LockColors",
                     "Lock Colors", "Appearance",
                     "Locks the color properties."));
    if (!LockColors)
    {
        items.Add(new DesignerActionPropertyItem("BackColor",
                         "Back Color", "Appearance",
                         "Selects the background color."));
        items.Add(new DesignerActionPropertyItem("ForeColor",
                         "Fore Color", "Appearance",
                         "Selects the foreground color."));

        //This next method item is also added to the context menu 
        // (as a designer verb).
        items.Add(new DesignerActionMethodItem(this,
                         "InvertColors", "Invert Colors",
                         "Appearance",
                         "Inverts the fore and background colors.",
                          true));
    }
    items.Add(new DesignerActionPropertyItem("Text",
                     "Text String", "Appearance",
                     "Sets the display text."));

    //Create entries for static Information section.
    StringBuilder location = new StringBuilder("Location: ");
    location.Append(colLabel.Location);
    StringBuilder size = new StringBuilder("Size: ");
    size.Append(colLabel.Size);
    items.Add(new DesignerActionTextItem(location.ToString(),
                     "Information"));
    items.Add(new DesignerActionTextItem(size.ToString(),
                     "Information"));

    return items;
}
Public Overrides Function GetSortedActionItems() _
As DesignerActionItemCollection
    Dim items As New DesignerActionItemCollection()

    'Define static section header entries.
    items.Add(New DesignerActionHeaderItem("Appearance"))
    items.Add(New DesignerActionHeaderItem("Information"))

    'Boolean property for locking color selections.
    items.Add(New DesignerActionPropertyItem( _
    "LockColors", _
    "Lock Colors", _
    "Appearance", _
    "Locks the color properties."))

    If Not LockColors Then
        items.Add( _
        New DesignerActionPropertyItem( _
        "BackColor", _
        "Back Color", _
        "Appearance", _
        "Selects the background color."))

        items.Add( _
        New DesignerActionPropertyItem( _
        "ForeColor", _
        "Fore Color", _
        "Appearance", _
        "Selects the foreground color."))

        'This next method item is also added to the context menu 
        ' (as a designer verb).
        items.Add( _
        New DesignerActionMethodItem( _
        Me, _
        "InvertColors", _
        "Invert Colors", _
        "Appearance", _
        "Inverts the fore and background colors.", _
        True))
    End If
    items.Add( _
    New DesignerActionPropertyItem( _
    "Text", _
    "Text String", _
    "Appearance", _
    "Sets the display text."))

    'Create entries for static Information section.
    Dim location As New StringBuilder("Location: ")
    location.Append(colLabel.Location)
    Dim size As New StringBuilder("Size: ")
    size.Append(colLabel.Size)

    items.Add( _
    New DesignerActionTextItem( _
    location.ToString(), _
    "Information"))

    items.Add( _
    New DesignerActionTextItem( _
    size.ToString(), _
    "Information"))

    Return items
End Function

備註

類別 DesignerActionPropertyItem 代表智慧標記面板中的個別專案。 每個專案通常會與類別中的屬性相關聯,該類別衍生自 DesignerActionList 類別,並由元件作者提供。 關聯是透過屬性的名稱來維護,如同儲存在屬性中 MemberName 一樣。

個別面板專案會與一起建立面板,方法是呼叫 GetSortedActionItems 類別的 DesignerActionList 方法來形成面板。

若要顯示相關聯屬性的值,該屬性必須有 get 存取子方法;若要允許編輯,屬性必須有 set 存取子方法。 面板允許使用者直接編輯屬性專案的方式,取決於相關聯屬性之數據類型的支援類型資訊。 下表顯示可能的配置。

屬性類型資訊 屬性專案編輯使用者介面 (UI)
具有相關聯的類型編輯器 (UITypeEditor) 與基礎屬性相關聯的類型編輯器隨即顯示,以便編輯屬性的值。
具有已知型別的 TypeConverter 關聯型別轉換器 () 已知類型的類型編輯器隨即顯示,用於編輯屬性的值。 例如,的 String 型別轉換子可能會顯示 TextBox
布林值 專案會使用二進位UI來顯示,例如複選標記。
以上皆非。 專案會使用資料類型的 ToString 方法顯示為不可編輯的文字字串。

所有基本類型,例如 System.Boolean,以及常見的 .NET Framework 數據類型,例如 System.String,提供標準類型轉換器和編輯器。 如需類型轉換器的詳細資訊,請參閱 如何:實作類型轉換器一般化類型轉換。 如需類型編輯器的詳細資訊,請參閱如何:實作UI類型編輯器

建構函式

DesignerActionPropertyItem(String, String)

使用指定的屬性和顯示名稱,初始化 DesignerActionPropertyItem 類別的新執行個體。

DesignerActionPropertyItem(String, String, String)

使用指定的屬性和分類名稱,以及顯示文字,初始化 DesignerActionPropertyItem 類別的新執行個體。

DesignerActionPropertyItem(String, String, String, String)

使用指定的屬性和分類名稱,以及顯示和說明文字,初始化 DesignerActionPropertyItem 類別的新執行個體。

屬性

AllowAssociate

取得或設定值,指出是否允許這個項目置於具有相同 Category 屬性值的項目群組中。

(繼承來源 DesignerActionItem)
Category

取得項目的群組名稱。

(繼承來源 DesignerActionItem)
Description

取得項目的補充文字。

(繼承來源 DesignerActionItem)
DisplayName

取得這個項目的文字。

(繼承來源 DesignerActionItem)
MemberName

取得與這個項目相關聯之屬性的名稱。

Properties

取得集合的參考,可用於儲存程式設計人員定義的索引鍵/值組。

(繼承來源 DesignerActionItem)
RelatedComponent

取得或設定元件,該元件將其項目提供給目前的面板。

ShowInSourceView

取得或設定值,這個值表示此項目是否出現在原始程式碼檢視中。

(繼承來源 DesignerActionItem)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱