Window2.CommandBars 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对窗口中包含的与 对象关联的 Microsoft Office CommandBars 集合的 WindowObject 引用。
public:
property System::Object ^ CommandBars { System::Object ^ get(); };
public object CommandBars { get; }
member this.CommandBars : obj
Public ReadOnly Property CommandBars As Object
属性值
实现
示例
注意:以下示例需要对 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.<span class="label">CommandBars</span>;
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);
注解
CommandBars 集合只能用于完全受信任的表单。 如果 CommandBars 集合由没有完全受到信任的表单使用,则该集合将返回“权限被拒绝”错误。