Compartilhar via


Window2.CommandBars Propriedade

Definição

Obtém uma referência à coleção CommandBars do Microsoft Office contida na janela associada ao WindowObject objeto.

public:
 property System::Object ^ CommandBars { System::Object ^ get(); };
public object CommandBars { get; }
member this.CommandBars : obj
Public ReadOnly Property CommandBars As Object

Valor da propriedade

Implementações

Exemplos

Observação: o exemplo a seguir requer uma referência ao namespace 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);

Comentários

A coleção CommandBars só pode ser usada por formulários totalmente confiáveis. Se usado por um formulário que não é totalmente confiável, a coleção CommandBars retornará um erro de "permissão negada".

Importante: esse membro só pode ser acessado por formulários abertos a partir de um modelo de formulário que foi configurado para ser executado com total confiança usando a categoria Segurança e Confiança da caixa de diálogo Opções de Formulário. This member requires full trust for the immediate caller and cannot be used by partially trusted code. For more information, see "Using Libraries from Partially Trusted Code" on MSDN.

Aplica-se a