Creates a command bar that is saved and available the next time the environment is started.
Assembly: EnvDTE (in EnvDTE.dll)
'Declaration Function AddCommandBar ( _ Name As String, _ Type As vsCommandBarType, _ CommandBarParent As Object, _ Position As Integer _ ) As Object
- Type: System.String
Required. A name for the new command bar.
- Type: EnvDTE.vsCommandBarType
Required. A vsCommandBarType constant that determines the type of command bar:
- Type: System.Object
- Type: System.Int32
Optional. The index position, starting at one, in the command bar to place the new command bar.
The CommandBar object is a member of the Microsoft Office object model.
The command bar added by using this method is a permanent command bar, which is available in every session of the IDE whether or not the add-in is loaded. You should use this method to add a command bar only if you want a permanent command bar. You should call this method only once, when your add-in is loaded for the first time. If you want a temporary command bar, which appears only when the add-in is actually loaded, you must use the DTE.CommandBars.Add method when you load the add-in, and then call DTE.CommandBars.Remove method when you unload the add-in.
Since a permanent command bar appears even when the add-in is not loaded, you should be sure to remove it when the add-in is uninstalled. Therefore, you must use an MSI to install and uninstall your add-in, and add a custom action to your uninstall program.
For more information about adding and removing permanent and temporary command bars, see HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in and HOWTO: Removing commands and UI elements during Visual Studio .NET add-in uninstallation.
' Macro code. Imports Microsoft.VisualStudio.CommandBars Sub AddCommandBarExample() ' Before running, you must add a reference to the Office ' typelib to gain access to the CommandBar object. Also, for this ' example to work correctly, there should be an add-in available ' in the Visual Studio environment. Dim cmds As Commands Dim cmdobj As Command Dim customin, customout As Object Dim cmdbarobj As CommandBar Dim colAddins As AddIns ' Set references. colAddins = DTE.AddIns() cmds = DTE.Commands cmdobj = cmds.Item("File.NewFile") ' Create a toolbar and add the File.NewFile command to it. cmdbarobj = cmds.AddCommandBar("Mycmdbar", _ vsCommandBarType.vsCommandBarTypeToolbar) MsgBox("Commandbar name: " & cmdbarobj.Name) cmdobj = cmds.AddNamedCommand(colAddins.Item(1), "mycommand", _ "mycommand", "tooltip for mycommand", True) End Sub
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.