DesignerActionList.GetSortedActionItems 方法


返回包含在列表中的 DesignerActionItem 对象的集合。Returns the collection of DesignerActionItem objects contained in the list.

 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 数组,包含此列表中的项。A DesignerActionItem array that contains the items in this list.


下面的代码示例演示如何创建对象的集合 DesignerActionItemThe following code example demonstrates how to create a collection of DesignerActionItem objects.

有关此代码示例的完整说明,请参阅 如何:将智能标记附加到 Windows 窗体组件For a complete explanation of this code example, see How to: Attach Smart Tags to a Windows Forms Component.

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",
                         "Inverts the fore and background colors.",
    items.Add(new DesignerActionPropertyItem("Text",
                     "Text String", "Appearance",
                     "Sets the display text."));

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

    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.", _
    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: ")
    Dim size As New StringBuilder("Size: ")

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

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

    Return items
End Function


virtual GetSortedActionItems 实现方法以按预期的显示顺序返回派生自类的对象的集合 DesignerActionItemThe virtualGetSortedActionItems method is implemented to return, in the expected display order, a collection of objects derived from the DesignerActionItem class. 这些项可以是以下特定类型。These items can be of the following specific types.

类型Type 说明Description
DesignerActionHeaderItem 以粗体显示的组标签。The group label, displayed in bold.
DesignerActionTextItem 以普通字体显示的标签。A label, displayed in a plain font.
DesignerActionPropertyItem 与属性关联的面板项。A panel item associated with a property. 还可能显示与基础属性关联的复选标记或属性编辑器。May also display a check mark or property editor associated with the underlying property.
DesignerActionMethodItem 显示为超链接并与方法关联的面板项。A panel item displayed as a hyperlink and associated with a method.

对于每个 DesignerActionMethodItemDesignerActionPropertyItem ,必须将相应的方法或属性添加到从类派生的程序员提供的类 DesignerActionListFor every DesignerActionMethodItem and DesignerActionPropertyItem, a corresponding method or property must be added to the programmer-supplied class derived from the DesignerActionList class. 每个方法和属性项都显示为一个活动项;通过用户界面 (UI 交互) 调用相应的方法或属性。Each method and property item is displayed as an active entry; interacting with it through the user interface (UI) invokes the corresponding method or property, respectively.

属性项具有一个特殊的面板项接口,该接口允许显示和操作其相应的属性值。Property items have a special panel-item interface that enables display and manipulation of their corresponding property values. 有关更多信息,请参见 DesignerActionPropertyItem 类。For more information, see the DesignerActionPropertyItem class.

返回数组中的项的顺序反映了它们在面板中的显示顺序。The order of the items in the returned array reflects the order that they will appear in the panel. 使用以下规则根据属性对项进行分组 CategoryThe items are grouped according to the Category property, using the following rules:

  • 遇到的第一项的类别表示第一个组的开始。The category of the first item encountered signifies the start of the first group. 只要每个后续项属于同一类别,该组就会继续。That group continues as long as each succeeding item is of the same category. 当遇到不同的新类别的项时,将创建一个新组,并将项放入其中。When an item of a different, new category is encountered, a new group is created and the item is placed in it.

  • 如果项的类型不同于当前组,但该类别已被使用,则该项将被放入匹配的现有类别。If an item has a type different than the current group, but that category has already been used, the item is placed in the matching existing category.

  • 如果项没有类别,则会将其放置在面板末尾的其他组中。If an item does not have a category, it is placed in a miscellaneous group at the end of the panel. 此组还包含 AllowAssociate 属性设置为的项 falseThis group also contains items whose AllowAssociate property is set to false.

GetSortedActionItems首次创建面板时,将调用方法。The GetSortedActionItems method is called when the panel is first created. 必须调用 Refresh 方法以更新面板中显示的项的列表。You must call the Refresh method to update the list of items displayed in the panel.