共用方式為


Window2.CommandBars 屬性

取得在與 WindowObject 物件關聯之視窗中所包含的 Microsoft Office CommandBars 集合參照。

**命名空間:**Microsoft.Office.Interop.InfoPath
**組件:**Microsoft.Office.Interop.InfoPath (於 microsoft.office.interop.infopath.dll 中)

語法

'宣告
<DispIdAttribute(1)> _
ReadOnly Property CommandBars As Object
'用途
Dim instance As Window2
Dim value As Object

value = instance.CommandBars
[DispIdAttribute(1)] 
Object CommandBars { get; }

備註

CommandBars 集合僅可由完全信任的表單使用。如果由不完全信任的表單使用,則 CommandBars 集合會傳回「使用權限遭拒」的錯誤。

範例

注意

下列範例需要 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);

請參閱

參考

Window2 介面
Window2 成員
Microsoft.Office.Interop.InfoPath 命名空間