下面的示例展示了如何为某个容器项中的特定子项设置焦点。

mFile (BarSubItem 类) 项的菜单被激活。 为了执行此操作,调用了 BarCustomContainerItemLink.OpenMenu 方法。 在该菜单被打开之后,我们使用 BarItemLink.Focus 方法把焦点设置到它的第一个子项上。

结果显示如下:

C#CopyCode image复制代码
// The item and its link for which the menu should be opened
BarSubItem containerItem = mFile;
BarSubItemLink containerLink = containerItem.Links[0] as BarSubItemLink;
// Open the menu for the link
containerLink.OpenMenu();
// Focus the first link in the menu opened
containerLink.VisibleLinks[0].Focus();            

Visual BasicCopyCode image复制代码
' The item and its link for which the menu should be opened
Dim containerItem As BarSubItem = mFile
Dim containerLink As BarSubItemLink = CType(containerItem.Links[0], BarSubItemLink)
' Open the menu for the link
containerLink.OpenMenu()
' Focus the first link in the menu opened
containerLink.VisibleLinks[0].Focus()