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.DesignerActionItemCollection
Public 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
注解
virtual
GetSortedActionItems实现 方法是为了按预期显示顺序返回派生自 DesignerActionItem 类的 对象的集合。 这些项可以是以下特定类型。
类型 | 说明 |
---|---|
DesignerActionHeaderItem | 以粗体显示的组标签。 |
DesignerActionTextItem | 以纯字体显示的标签。 |
DesignerActionPropertyItem | 与属性关联的面板项。 还可以显示与基础属性关联的检查标记或属性编辑器。 |
DesignerActionMethodItem | 显示为超链接并与方法关联的面板项。 |
对于每个 DesignerActionMethodItem 和 DesignerActionPropertyItem,必须将相应的方法或属性添加到从 类派生 DesignerActionList 的程序员提供的类中。 每个方法和属性项显示为活动条目;通过用户界面 (UI 交互) 分别调用相应的方法或属性。
属性项具有特殊的面板项接口,用于显示和操作其相应的属性值。 有关更多信息,请参见 DesignerActionPropertyItem 类。
返回数组中项的顺序反映了它们在面板中出现的顺序。 使用以下规则根据 Category 属性对项进行分组:
遇到的第一个项的类别表示第一个组的开始。 只要每个后续项属于同一类别,该组就将继续。 当遇到不同类别的项时,将创建一个新组并将该项放入其中。
如果项的类型与当前组不同,但已使用该类别,则该项将置于匹配的现有类别中。
如果某个项没有类别,则将其置于面板末尾的杂项组中。 此组还包含属性设置为
false
的AllowAssociate项。
首次 GetSortedActionItems 创建面板时调用 方法。 必须调用 Refresh 方法才能更新面板中显示的项列表。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈