Command Bars

A command bar is a menu bar or toolbar; from an object model perspective, these are represented by CommandBar objects. Because menu bars and toolbars are hosted within a window, you reference specific CommandBar objects via the Window object through the Window.CommandBars property. In turn, every CommandBar plays host to controls such as buttons and drop-downs. Figure 14.5 shows the Solution Explorer tool window with its command bar highlighted.

Image

FIGURE 14.5 The Solution Explorer’s command bar.


Note

Unlike the Windows collection, which holds only an instance of each open window, the CommandBars collection holds instances for every registered command bar, regardless of whether the command bar is currently being shown in the window. Also note that working with the CommandBar and CommandBars objects will require a reference to Microsoft.VisualStudio.CommandBars. This using statement is not included by default with add-in project class templates.



Tip

Use the CommandBar.Type property to determine whether a command bar is a toolbar or a menu bar. A value of MsoBarType.msoBarTypeNormal indicates that the command bar is a toolbar, whereas a value of MsoBarType.msoBarTypeMenuBar indicates that the command bar is a menu bar.


The CommandBar object properties and methods are documented in Table 14.10.

Image
Image

TABLE 14.10 CommandBar Members


Note

Earlier versions of Visual Studio actually relied on a Microsoft Office assembly for the CommandBar object definition (Microsoft.Office.Core). Visual Studio 2005 and later versions provide their own implementation of the CommandBar object that is defined in the Microsoft.VisualStudio.CommandBars namespace, although you will find some types that carry their nomenclature over from the Microsoft Office assembly, such as the various MsoXXX enums.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset