DesignerActionList.GetSortedActionItems 方法

定義

傳回包含於清單中的 DesignerActionItem 物件集合。

public:
 virtual System::ComponentModel::Design::DesignerActionItemCollection ^ GetSortedActionItems();
public virtual System.ComponentModel.Design.DesignerActionItemCollection GetSortedActionItems ();
abstract member GetSortedActionItems : unit -> System.ComponentModel.Design.DesignerActionItemCollection
override this.GetSortedActionItems : unit -> System.ComponentModel.Design.DesignerActionItemCollection
Public Overridable Function GetSortedActionItems () As DesignerActionItemCollection

傳回

DesignerActionItem 陣列,包含這個清單中的項目。

範例

下列程式代碼範例示範如何建立 物件的集合 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

備註

方法 virtualGetSortedActionItems 會實作,以預期顯示順序傳回衍生自 DesignerActionItem 類別的物件集合。 這些專案可以是下列特定類型。

類型 說明
DesignerActionHeaderItem 群組標籤,以粗體顯示。
DesignerActionTextItem 以純字型顯示的標籤。
DesignerActionPropertyItem 與屬性相關聯的面板專案。 也可能顯示與基礎屬性相關聯的複選標記或屬性編輯器。
DesignerActionMethodItem 顯示為超連結且與方法相關聯的面板專案。

針對每個 DesignerActionMethodItemDesignerActionPropertyItem,必須將對應的方法或屬性新增至衍生自 DesignerActionList 類別的程式設計人員提供的類別。 每個方法和屬性專案都會顯示為使用中專案;透過使用者介面與其互動, (UI) 分別叫用對應的方法或屬性。

屬性專案具有特殊的面板專案介面,可顯示及操作其對應的屬性值。 如需詳細資訊,請參閱 DesignerActionPropertyItem 類別。

傳回數位中項目的順序會反映它們出現在面板中的順序。 項目會根據 Category 屬性分組,使用下列規則:

  • 第一個項目的類別表示第一個群組的開頭。 只要每個成功的專案都屬於相同的類別,該群組就會繼續。 當遇到不同類別的專案時,就會建立新的群組,並將專案放在其中。

  • 如果項目的類型與目前群組不同,但已使用該類別,該專案就會放在相符的現有類別中。

  • 如果項目沒有類別,它會放在面板結尾的其他群組中。 此群組也包含屬性設定為false的專案AllowAssociate

GetSortedActionItems 一次建立面板時會呼叫 方法。 您必須呼叫 Refresh 方法來更新面板中顯示的項目清單。

適用於

另請參閱