The NetXP Command Bar Suite

Introduction

The command bar suite in NetXP is one of the most important aspects of NetXP. They enable a complete unification of menus and toolbars and provide an excellent user interface virtually identical to the one found in many Microsoft applications, including Office 2003. Through custom extensible rendering, the NetXP command bars support Office 2003, Office XP, and Windows XP visual styles. Because renderers are extensible, you can also define your own custom look and feel in your own applications.

Getting Started With Command Bars

Using command bars in your applications is designed to be as simple and straight-forward as possible. To create a simple command bar application, create a new Windows Forms application then follow the steps below.

  1. Add the NETXP.Controls.Bars.dll assembly to your toolbox if necessary.
  2. Drag and drop the CommandBarManager component onto your form.
  3. Select the command bar manager and click Add Command Bar in the properties window.
  4. The first command bar we will add should be a menu bar, so the next few steps will describe how to change the existing command bar to a menu bar.
  5. Select the top toolbar container on the form. This is called a CommandBarDock and it contains one or more command bars, managing their layout. There are four default CommandBarDock controls added to a form when the CommandBarManager object is added. These are docked to each of the four sides of the form and are necessary to provide full floating command bar support.
  6. Select the command bar inside the command bar dock. It should be called commandBar1.
  7. Go to the properties window and change the Style property to Menu. Notice how the command bar has changed to occupy the full row. Note: You should never add more than one menu bar to a form, since the menu bar hooks certain keyboard events, and if there is more than one menu bar, both bars might respond simultaneously to the same keyboard event.
  8. Next we need to add some menu items to the menu bar. At the bottom of the properties window you should see a few links. These are quick links for adding items to a command bar. Click the Add Button link. A new button item is created. A button item on a menu bar translates into a top-level menu item.
  9. In the properties window set the Text property of the item to "&File" (no quotes).
  10. Select the Items property and click the [...] button. This allows you to edit the collection of sub-items for this item. Editing the Items property is another way to view and edit command bar items.
  11. On the Add button you will notice a drop-down arrow. This means there are multiple types of items that can be added. Click the drop-down arrow and choose CommandBarButtonItem. A new CommandBarButtonItem is added. Set its Text property to "E&xit" (no quotes). Set its Shortcut property to AltF4. You can optionally also set an image to this item if you wish by changing the Image property.
  12. Click OK. The only menu item we will have for now is File -> Exit.
  13. Select the command bar manager again. Choose Add Command Bar.
  14. Select the newly-added command bar. This will be our toolbar.
  15. Click Add Button from the bottom of the property window.
  16. Specify an image property for the item by setting the Image property, or set the Text property to something and then set ShowText to True.
  17. You can add more items to the menu and toolbar if you wish, following the same procedures described above.
  18. Select the File -> Exit item by clicking the File menu item and then clicking the Exit item. Assign a Click event handler to the item. Inside the handler, close the form.

This simple tutorial has now taught you the basics of using the command bar suite in NetXP.

Using Command Bars With MDI Forms

To use command bars with MDI forms, you must assign your MDI client to the main menu bar, as the MdiContainer property. In the designer, select the main menu bar and select the MdiContainer property in the property grid. Open the drop-down list and choose your form object from the list. MDI support is now added to the menu bar. The MDI widgets will now be shown on the menu bar when an MDI child is opened.

Saving and Loading Layout

The command bars in NetXP 3.0 support saving and loading layouts.

To save the current layout, use the various overloads of CommandBarManager.SaveLayout. You can save the layout to a registry key, a binary stream, or an XML stream.

To load a layout, you can use the various overloads of CommandBarManager.LoadLayout. You can load the layout from a registry key, a binary stream, or an XML stream.

Stand-Alone Command Bars

You can use command bars as stand-alone controls. Instead of adding a command bar manager, add a command bar instead. The command bar will not be movable by the user nor will it have a size gripper. By default it will have the same background as its container, but you can specify another background color or image.

Showing and Hiding Command Bars

To show or hide a command bar, don't use the control's Show or Hide method, but rather the ShowBar and HideBar methods, respectively. These will show or hide a bar properly even if the bar is floating. Also, when a bar has been shown or hidden, a VisibleChanged notification is raised, which allows you to update any menu items to indicate whether or not the bar is showing.

Control Container Items

Not only are you allowed to have combo box items in a command bar, but you can add items that host any Windows Forms control. You can only add CommandBarControlItem objects to an item collection at runtime, since they're not supported in the designer. For example, to add a control item that hosts a Button control, refer to this code:

	CommandBarControlItem ctlItem = new CommandBarControlItem();
	this.commandBar2.Items.Add(ctlItem);
	ctlItem.Control = new Button();
	ctlItem.Control.Text = "Button Item";
	ctlItem.Width = 70;
	ctlItem.Height = 20;
	(ctlItem.Control as Button).FlatStyle = FlatStyle.System;

For more information on command bars, please see the NetXP reference documentation.