Customizing Microsoft Office commandbars
with custom controls in VB.NET, C#, C++
Toolbar Controls Add-in Express Home > Toolbar Controls for Microsoft Office > Online Guide > Insight of Toolbar Controls This page explains nuts and bolts of of Toolbar Controls for Microsoft Office, which is part of Add-in Express for Office and .net. To make the text below easy to read, let's define three terms, namely:
Further on this page you will find information about:
Note. This feature cannot be used to customize a CommandBar control shown in the Ribbon user interface. What is ADXCommandBarAdvancedControlIf you have developed at least one add-in based on Add-in Express, you probably ran into ADXCommandBarAdvancedControl when adding command bar controls to your command bars. Yes, it is that strange item of the Add button on the ADXCommandBarControl collection editor. This plug-in gives you a chance to use any non-Office controls such as tree-views, grids, labels, edit and combo boxes, diagrams on any Office command bars. Now you can add ADXCommandBarAdvancedControl, an advanced command bar control, to your command bar and bind it to any non-Office control you placed on the add-in module. As a result, you will have your grid, tree-view or image placed on your command bar. Hosting any .NET controlsIn addition to properties common for Office command bar controls, ADXCommandBarAdvancedControl has one more property. It is the Control property, the most important one. With this property, you can select a non-Office control to place it on your command bar. Have a look at the picture below. The add-in module contains five controls - MyCalendar, MyDataGrid, MyNumericUpDown, MyTreeView and MyUserControl. The Control property asks you to select one of these controls. If you select MyUserControl, your add-in adds MyUserControl to your command bar. With the Control property, DXCommandBarAdvancedControl becomes a host for your non-Office controls. On .NET, ADXCommandBarAdvancedControl supports all controls based on System.Windows.Forms.Control. So, on your command bars, you can use both built-in controls and third-party controls based on System.Windows.Forms.Control. Just add them to the add-in module, add an advanced command bar control to your command bar and select your non-Office control in the Control property of ADXCommandBarAdvancedControl. The Toolbar Controls is a set of control adaptersYou may ask us what the Toolbar Controls described above does, if ADXCommandBarAdvancedControl is already included in Add-in Express. In general, ADXCommandBarAdvancedControl is still abstract in Add-in Express, but it is implemented by the Toolbar Controls if it is plugged into Add-in Express. So, our answer is: the Toolbar Controls for Microsoft Office implements ADXCommandBarAdvancedControl for each Office application. The Toolbar Controls adds a new tab, "Toolbar Controls for Microsoft Office", to the Toolbox and places several components on the tab (see the picture below). The Toolbar Controls supports each Office application by special components that we call Control Adapters. Only Control Adapters know how to add your controls to applications specific command bars. So, the Control Adapters are the Toolbar Controls itself. In Express editions of Visual Studio, you need to add the control adapters manually. The add-in module can contain control adapters only. For example, you should add an ADXExcelControlAdapter to the add-in module if you want to use non-Office controls in your Excel add-in. To use non-Office controls on several Office applications you should add several control adapters. For example, if you need to use your controls in your add-in that supports Outlook, Excel, and Word, you should add three control adapters: ADXExcelControlAdapter, ADXWordControlAdapter, and ADXOutlookControlAdapter to the add-in module. ADXCommandBarAdvancedControl propertiesThe Toolbar Controls implements the ADXCommandBarAdvancedControl class. In addition to properties common for all command bar controls, ADXCommandBarAdvancedControl provides two special properties related to the Toolbar Controls. The Control propertyThe Control property binds its ADXCommandBarAdvancedControl to a non-Office control and can be used at design-time as well as at run-time. To place your non-Office control on your command bar you just select your control in the Control property at design-time, or set the Control property to an instance of your control at run-time: VB.NET
The ActiveInstance propertyThe ActiveInstance property is read-only and returns the instance of the Control that was created for the current context. For example, you can initialize your control for the active Inspector by handling the InspectorActivate event: VB.NET
Please note, the ActiveInstance property is not actual in most cases when you'd like to use it. You can always use any window activate events such as the InspectorActivate event of Outlook and WindowActivate event of Word. The table below shows you the order of event processing by the example of the Outlook Inspector window opened by the user.
Control adaptersAAll Office applications have different window architectures. All Office windows themselves are different. All our control adapters have a unified programming interface but different internal architectures that take into account the windows architecture of the corresponding applications. All features of all control adapters are described below. OutlookOutlook has two main windows - Explorer and Inspector windows. The user can open several Explorer and Inspector windows. Our Outlook control adapter supports non-Office controls on both the Explorer and Inspector windows, and creates an instance of your control whenever the user opens a new Explorer or Inspector window. Please note, if Word is used as an e-mail editor, Outlook uses MS Word as an Inspector window. In this case, Word is running in a separate process. It does not provide any ways to control all instances of your control. So, there is one feature with Word as an e-mail editor: the Outlook control adapter hides all instances of your control on all inactive Word Inspector windows, but shows them once the Inspector is activated. See also a sample project showing how to add a custom .NET control to Outlook commandbar. ExcelIn spite of the fact that Excel allows placing its windows on the Task Bar, all its commandbars work like in MDI applications. So, your controls are created only once, when Excel is started. However, you can still use the WorkbookActivate, WindowActivate and SheetActivate events to initialize your non-Office controls according to the context. WordWord creates its commandbars for all document windows, so your non-Office controls are instanced whenever the user opens a new window or a document. We recommend using the WindowActivate event to initialize your control for the current window. PowerPointNotwithstanding the fact that PowerPoint makes possible placing its windows on the Task Bar, PowerPoint is an MDI application. So, your controls are created only once, when PowerPoint is started. However, you can still use the WindowActivate event to initialize your non-Office controls according to the context. |