Share via


Window2.CommandBars Property

Gets a collection of Microsoft.VisualStudio.CommandBars contained in the current window.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

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

Property Value

Type: System.Object
A Microsoft.VisualStudio.CommandBars collection.

Examples

This example iterates through the CommandBars collection for the Object Browser window, and then displays the caption of each command in a message box.

For more information on how to run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

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 Security

See Also

Reference

Window2 Interface

EnvDTE80 Namespace