Window2.CommandBars 属性

定义

获取对与 对象关联的窗口中包含的 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 集合由没有完全受到信任的表单使用,则该集合将返回“权限被拒绝”错误。

重要说明:此成员只能由已配置为使用“表单选项”对话框的“安全与信任”类别以完全信任方式运行的表单模板打开的表单访问。 此成员要求直接调用方的完全信任并且不能由部分信任的代码使用。 有关更多信息,请参阅 MSDN 上的“使用部分信任的代码中的库”。

适用于