Walkthrough: Context Menus

Review the Context menu topic in order to become familiar with how a context menu works.

This walkthrough is split up into the following activities.

This walkthrough yields an application that resembles the following.

Creating a Popup menu

To create a Popup menu
  1. Create a new project and add the ActiveBar control to your project. (See Adding ActiveBar to a Project.)
  2. Right-click the ActiveBar control and select Properties to display the ActiveBar Designer.
  3. Right-click the Categories node in the Designer tree view and select Insert.
  4. Select the new category and press F2  to rename the category Context Menu.
  5. Add a second category named Other.
  6. Right click the Context Menu category and add these buttons.
    Category ID Name Caption Type Description
    Context Menu 101 newMenuItem &New Button Creates a new document
    102 openMenuItem &Open Button Opens a document.
    103 saveMenuItem &Save Button Saves the active document.
    104 printMenuItem &Print Button Prints the active document.
    105 exitMenuItem E&xit Button Exits application.
  7. Add an icon to each button. (See Icon Editor.)
  8. Right-click on the Other category and add a Separator tool. Rename the Separator tool menuSeparator and remove the default text from the Caption property.
  9. Right-click the Bands node, select Popup Menu, and rename the Popup band contextMenu.
  10. Use your mouse and the SHIFT or CTRL key to select all of the tools in the Context menu category and drag them onto contextMenu.
  11. Drag menuSeparator from the Other category and drop it onto tools in contextMenu to logically organize them by function.
  12. Click OK to return to the form.

Adding code to make the Popup menu a context menu

To add code to make the Popup menu a context menu
  1. In the code view of the form, select ActiveBar31 in the Object list and MouseUp in the Procedure list to create the MouseUp event.
  2. Add the following code to the MouseUp event to display the context menu at the current coordinates of the mouse pointer.

    Private Sub ActiveBar31_MouseUp(Button As Integer, shift As Integer, x As Single, y As Single) If Button = vbRightButton Then ActiveBar31.Bands("contextMenu").PopupMenu End If End Sub

  3. Press F5 to run the application.
  4. Right-click on the form to display the context menu.

Context Menu | Adding ActiveBar to a Project

 

 


Copyright © 2006 Data Dynamics, Ltd. All Rights Reserved.