Working with the CommandBar Control

A CommandBar control is a container for other controls, such as menus, combo boxes, and buttons. The CommandBar control is a Windows CE-specific toolbar. The CommandBar control provides menu features and buttons, such as Close and Help, that are similar to those provided in Microsoft® Pocket Internet Explorer.

The CommandBar control also can contain separators that divide other elements into groups. On the CommandBar control, a menu is represented by an Item object, a combo box is represented by a CommandBarComboBox object, and a button is represented by a CommandBarButton object.

The Style property determines the appearance and behavior of each control. Based on the options you choose for the Style property, each type of control on a CommandBar can behave in different ways. For example, a button can behave as an option button or as a standard command button.

The first step in using a CommandBar control is to place the control on a form. A CommandBar control can be any width, but the height is determined automatically by the number and size of the controls it contains. Although you can place the CommandBar control anywhere on the form, the CommandBar typically replaces the Visual Basic title bar.

    To add a CommandBar control to the top of a form

  1. Double-click the CommandBar icon in the Toolbox. The toolkit places a small CommandBar control in the middle of your form.
  2. Move the CommandBar to the top of the form.
  3. Change the BorderStyle property of the Form to 0 to remove the title bar from the form.
  4. Select the form. A window containing the code for the Form.Load event opens.
  5. Enter the following code to the Form.Load event to set the CommandBar to its maximum width.
    Commandbar.Width = me.width
    

After you place the CommandBar on a form, it contains the default buttons OK, Cancel, and Help, but it does not contain any controls. To add controls to the CommandBar, use the Add method of the CommandBarControls collection.

Once you add member controls to the CommandBar control, the CommandBar reacts to user input by generating events. A CommandBar control generates a specific event for each type of member control. For example, when a user selects any CommandBarButton object, the control fires the ButtonClick event. You therefore must code the event to determine which particular CommandBarButton object was selected by the user.

You can add the following types of object to your CommandBar control:

All three types of CommandBar control inherit the properties of the CommandBarControl object.