Window2.CommandBars 属性
获取对 Microsoft Office CommandBars 集合的引用,该集合包含在与 WindowObject 对象相关联的窗口中。
命名空间: Microsoft.Office.Interop.InfoPath.SemiTrust
程序集: Microsoft.Office.Interop.InfoPath.SemiTrust(位于 Microsoft.Office.Interop.InfoPath.SemiTrust.dll 中)
语法
声明
ReadOnly Property CommandBars As Object
Get
用法
Dim instance As Window2
Dim value As Object
value = instance.CommandBars
Object CommandBars { get; }
属性值
实现
备注
CommandBars 集合只能用于完全受信任的表单。如果 CommandBars 集合由没有完全受到信任的表单使用,则该集合将返回"权限被拒绝"错误。
重要
只能由从表单模板打开的表单访问此成员,已使用"表单选项"对话框"安全和信任"类别将该模板配置为以完全信任状态运行。此成员要求直接调用方的完全信任并且不能由部分信任的代码使用。有关更多信息,请参阅 MSDN 上的"使用部分信任的代码中的库"。
示例
备注
以下示例需要一个对 System.Reflection 命名空间的引用。
BindingFlags flags = BindingFlags.GetProperty | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
// The CommandBars collection returns only one of the objects
// that implements an IDispatch interface.
// To perform checks and allow COM-like calls,
// you must create a wrapper by casting to the ObjectWrapper class.
ObjectWrapper commandBars = (ObjectWrapper)thisApplication.ActiveWindow.CommandBars;
int commandBarsCount = (int)commandBars.InvokeByName(
"Count", // prop
flags,
null, // arguments
null); // Culture
thisXDocument.UI.Alert("There are " + commandBarsCount.ToString() + " Command Bars");
// Either of the following two lines will work
object[] args = new object[] {1};
// object[] args = new object[] {"Standard"};
// This object is outside the wrapper - this gets a .NET object
object commandBarItem = commandBars.InvokeByName(
"Item",
flags,
args, // arguments
null); // Culture
thisXDocument.UI.Alert("Got the 'Standard' command bar");
string commandBarName = (string)commandBarItem.GetType().InvokeMember(
"name",
flags,
null,
commandBarItem,
null);
thisXDocument.UI.Alert(commandBarName);