共用方式為


Window2.CommandBars 屬性

取得目前視窗中所包含的 Microsoft.VisualStudio.CommandBars 集合。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
ReadOnly Property CommandBars As Object
Object CommandBars { get; }
property Object^ CommandBars {
    Object^ get ();
}
abstract CommandBars : Object
function get CommandBars () : Object

屬性值

型別:System.Object
Microsoft.VisualStudio.CommandBars 集合。

範例

這個範例會逐一查看 [物件瀏覽器] 視窗的 CommandBars 集合,並在訊息視窗中顯示每個命令的標題。

如需如何像執行增益集一般,執行這個範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

Imports EnvDTE
Imports EnvDTE80
Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    GetCommandBars(_applicationObject)
End Sub
Sub GetCommandBars(ByVal dte As DTE2)
    Dim win As Window2 = _
 CType(DTE.Windows.Item(Constants.vsWindowKindObjectBrowser), Window2)
    Dim cmdBars As CommandBars = CType(win.CommandBars, CommandBars)
    Dim aString As String = "The command bars in " & _
    win.Caption & " are called:" & vbCr
    For Each cmdBar As CommandBar In cmdBars
        aString = aString & (cmdBar.Name & vbCr)
    Next
    MsgBox(aString)
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    GetCommandBars(_applicationObject);
}
public void GetCommandBars(DTE2 dte)
{
    try
    {
        Window2 win =
 (EnvDTE80.Window2)_applicationObject.Windows.Item
(Constants.vsWindowKindObjectBrowser);
        CommandBars cmdBars = (CommandBars)win.CommandBars;
        String aString = null;
        aString = ("The command bars in " + win.Caption 
+ " are called:" + "\n");
        foreach (CommandBar cmdBar in cmdBars)
        {
            aString = aString + (cmdBar.Name + "\n");
        }
        MessageBox.Show(aString);
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

Window2 介面

EnvDTE80 命名空間