Window2.CommandBars - Propriété
Obtient une référence à la collection de CommandBars Microsoft Office contenue dans la fenêtre associée à l'objet WindowObject .
Espace de noms : Microsoft.Office.Interop.InfoPath
Assembly : Microsoft.Office.Interop.InfoPath (dans Microsoft.Office.Interop.InfoPath.dll)
Syntaxe
'Déclaration
ReadOnly Property CommandBars As Object
Get
'Utilisation
Dim instance As Window2
Dim value As Object
value = instance.CommandBars
Object CommandBars { get; }
Valeur de propriété
Type : System.Object
Implémentations
Remarques
La collection CommandBars ne peut être utilisée que par des formulaires avec autorisation totale. Si elle est utilisée par un formulaire qui ne dispose pas d'une autorisation totale, la collection CommandBars renvoie une erreur « autorisation refusée ».
Exemples
Notes
L'exemple suivant requiert une référence à l'espace de noms 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);