Window.CommandBars 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对与 对象关联的窗口的 Microsoft Office CommandBars 集合的 Window 引用。
public:
abstract property System::Object ^ CommandBars { System::Object ^ get(); };
public abstract object CommandBars { get; }
member this.CommandBars : obj
Public MustOverride ReadOnly Property CommandBars As Object
属性值
对与 对象关联的窗口的 Microsoft Office CommandBars 集合的 Window 引用。
例外
没有使用“表单选项”对话框的“安全和信任”类别将表单模板配置为“完全信任”。
示例
在以下示例中,类的 WindowCommandBars 属性用于获取 CommandBars 集合并显示命令栏的计数。
此示例要求在表单代码模块的声明部分中使用 Microsoft.Office.Core 命名空间的 using 或 Imports 指令。
// Get CommandBars collection casting to
// Microsoft.Office.Core.CommandBars type.
CommandBars myCommandBars =
(CommandBars)this.Application.ActiveWindow.CommandBars;
// Get count using CommandBars Count property.
int commandBarsCount = myCommandBars.Count;
// Display count of command bars.
MessageBox.Show("There are " + commandBarsCount.ToString() +
" Command Bars");
' Get CommandBars collection casting to
' Microsoft.Office.Core.CommandBars type.
Dim myCommandBars As CommandBars =
DirectCast(Me.Application.ActiveWindow.CommandBars, CommandBars)
' Get count using CommandBars Count property.
Dim commandBarsCount As Integer = myCommandBars.Count
' Display count of command bars.
MessageBox.Show("There are " & commandBarsCount.ToString() &
" Command Bars")
注解
在建立了对 CommandBars 集合的引用之后,可以访问该类的所有属性和方法。
重要提示:若要使 CommandBars 属性正常工作,必须使用 Visual Studio 2012 中“添加引用”对话框的“COM”选项卡建立对 Microsoft Office 14.0 对象库的引用。 这将建立一个对包含 CommandBars 类的 Microsoft.Office.Core 命名空间的引用。 此外,还必须将此表单作为完全信任的表单运行。
只能由从表单模板打开的表单访问此成员,已使用“表单选项”对话框“安全和信任”类别将该模板配置为以完全信任状态运行。 此成员要求直接调用方的完全信任并且不能由部分信任的代码使用。 有关更多信息,请参阅 MSDN 上的“使用部分信任的代码中的库”。
可以通过 Microsoft InfoPath Filler 中打开的表单中运行的代码访问此类型或成员。