DesignerActionList.GetSortedActionItems 方法      
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回列表中所包含的 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.DesignerActionItemCollectionPublic Overridable Function GetSortedActionItems () As DesignerActionItemCollection返回
包含此列表中的项的 DesignerActionItem 数组。
示例
下面的代码示例演示如何创建 DesignerActionItem 对象的集合。
有关此代码示例的完整说明,请参阅 如何:将智能标记附加到 Windows 窗体组件。
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 | 显示为超链接并与方法关联的面板项。 | 
对于每个 DesignerActionMethodItem 和 DesignerActionPropertyItem,必须将相应的方法或属性添加到从 DesignerActionList 类派生的程序员提供的类。 每个方法和属性项都显示为活动条目;通过用户界面(UI)与其交互分别调用相应的方法或属性。
属性项具有特殊的面板项接口,用于显示和操作相应的属性值。 有关详细信息,请参阅 DesignerActionPropertyItem 类。
返回数组中项的顺序反映了它们将显示在面板中的顺序。 这些项根据 Category 属性分组,使用以下规则:
- 遇到第一项的类别表示第一组的开头。 只要每个成功项都属于同一类别,该组就继续。 当遇到其他类别的项时,将创建一个新组,并将该项放入其中。 
- 如果某个项的类型与当前组不同,但已使用该类别,则该项将置于匹配的现有类别中。 
- 如果某个项目没有类别,则会将其放置在面板末尾的杂项组中。 此组还包含其 AllowAssociate 属性设置为 - false的项。
首次创建面板时会调用 GetSortedActionItems 方法。 必须调用 Refresh 方法来更新面板中显示的项列表。