.Net Controls: Context Menu

 

Overview

A menu is considered, or qualifies as, popup if, or because, it can appear anywhere on the form as the programmer wishes. Such a menu is also referred to as context-sensitive because its appearance and behavior depends on where it displays on the form or on a particular control.

The first difference between a main menu and a popup menu is that a popup menu appears as one category or one list of items and not like a group of categories of menus like a main menu. Secondly, while a main menu by default is positioned on the top section of a form, a popup menu doesn't have a specific location on the form.

To use a popup menu, usually the user can right-click the section of the form or the object on which the menu is configured to appear.

A popup menu is based on the ContextMenu class. To visually create a popup menu, on the Toolbox, click the ContextMenu button and click on the form. Once you have a ContextMenu object, you can create its menu items. To do this, click the ContextMenu box to display the first Type Here line and configure the menu item as you would proceed with a menu item on the main menu.

Unlike a main menu, a popup menu provides a single list of items. If you want different popup menus for your form, you have two options. You can create various popup menus or programmatically change your single popup menu in response to something or some action on your form.

There is nothing particularly specific with writing code for a popup menu item. You approach it exactly as if you were dealing with a menu item of a main menu. You can write code for an item of a popup menu independent of any other item of a main menu. If you want an item of a popup menu to respond to the same request as an item of a main menu, you can write code for one of the menu items (either the item on the main menu or the item on the popup menu) and simply call its Click event in the event of the other menu item

  1. On the Toolbox, scroll down, click the ContextMenu button and click on the form
  2. On the form, click the ContextMenu box
  3. Click the Type Here box. Type &Font... and press Enter
  4. Click the empty box under Font to select it. Type &Options and press Enter
  5. Type &Properties and press Enter
  6. Type - and press Enter
  7. Type Finis&h and press Enter
  8. Click Finish
  9. On the Properties window, click the Events button Events
  10. Click the Click field to display its combo box. Click the arrow of the right field and select the only item in the list, which corresponds to the Exit menu item of the main menu
  11. Click an empty area on the form to select the form
  12. In the Properties window, click the Properties button Properties and click the ContextMenu field
  13. Click the arrow of the ContextMenu property and select contextMenu1
  14. Execute the application
     
    Using context-sensitive help
  15. Right-click in the middle of the form and click Finish.

 

 

Home Copyright © 2004-2005 FunctionX, Inc.