Page 215 - Open Soource Technologies 304.indd
P. 215
Unit 9: Menus and Dialog Boxes
9.4.2 The Boldcommand Argument
We use the boldcommand argument to specify the name of a menu control in the displayed
pop-up menu that you want to appear in bold. Only one menu control in the pop-up menu can
be bold.
9.5 Controlling Menus at Run Time
The menus you create at design time can also respond dynamically to run-time conditions. For
example, if a menu item action becomes inappropriate at some point, we can prevent users from
selecting that menu item by disabling it. In the MDI NotePad application, for example, if the
clipboard doesn’t contain any text, the Paste menu item is dimmed on the Edit menu, and users
cannot select it.
We can also dynamically add menu items, if you have a menu control array. This is described
in “Adding Menu Controls at Run Time,” later in this topic.
We can also program your application to use a check mark to indicate which of several
commands was last selected. For example, the Options, Toolbar menu item from the MDI
NotePad application displays a check mark if the toolbar is displayed. Other menu control
features described in this section include code that makes a menu item visible or invisible and
that adds or deletes menu items.
9.5.1 Enabling and Disabling Menu Commands
All menu controls have an Enabled property, and when this property is set to False, the menu
is disabled and does not respond to user actions. Shortcut key access is also disabled when
Enabled is set to False. A disabled menu control appears dimmed, like the Paste menu item in
Figure 9.6.
Figure 9.6: A Disabled Menu Item.
For example, this statement disables the Paste menu item on the Edit menu of the MDI NotePad
application:
mnuEditPaste.Enabled = False
Disabling a menu title in effect disables the entire menu, because the user cannot access any menu
item without first clicking the menu title. For example, the following code would disable the
Edit menu of the MDI Notepad application:
mnuEdit.Enabled = False
LOVELY PROFESSIONAL UNIVERSITY 209