• No results found

D ESIGNING M ENU B UTTONS

In document Navision Bible (Page 164-168)

Extending the Functionality of Your Forms

8.5 D ESIGNING M ENU B UTTONS

While command buttons are a convenient way of adding functionality to forms, an excess of buttons will clutter the forms and impair their visual design. If you need to use many command buttons, you should consider creating menu buttons instead.

When a menu button is pushed, a menu is opened:

Each line in a menu is called a menu item. A menu item can:

· Perform an action when clicked. This can be an action from the same set of actions as command buttons (see the online C/SIDE Reference Guide for a list), or it can be an action written in C/AL, as menu items have OnPush triggers just like command buttons.

· Contain a submenu that is opened when the line is clicked.

· Be a separator – a line used for grouping items in a menu together.

A menu is created in two steps. First you add a menu button to your form. This part is exactly the same procedure as adding a command button. Then you open the Menu Designer for the menu button and create the menu items.

Adding a Menu Button to a Form To add a menu button:

1 Open the form in the Form Designer.

2 Choose the Menu Button tool, then click in the design area to add the menu button.

8.5 Designing Menu Buttons

3 Select the menu button and open the Property Sheet for the menu button. As a menu button does not have a relation to data – field or variable – Name and Caption are set to default values (like Control7). Change the Caption to an appropriate text. If the text contains an ampersand (&), the system interprets the following letter as an access key.

Adding a Menu Line to a Menu

When you have created and modified a menu button as described above, you can add lines to the menu that is displayed when the button is pushed.

To add a menu line:

1 Select the button and open the Menu Designer while the button is selected.

(Choose View, Menu Items.)

2 The first field, Visible, is by default set to Yes. Leave it like this.

3 Add lines by filling out the Caption field. If you do not create an access key yourself (by embedding an ampersand in the Caption text), the system will automatically use

4 If you want, you can define a shortcut key (accelerator key) by entering the name of the key in the ShortCutKey field. Keys are entered as follows:

An accelerator key is active as long as the focus is on the form that the menu button is a child of. Beware of accidentally overloading some key combinations so that they perform different actions when different forms have the focus – this could confuse the user. Also beware of using accelerator keys that the system already uses.

5 Enter the action for the menu item in the Action field. You can use the drop-down list that is available to choose from among the same actions as for a command button. You can also write C/AL code in the OnPush trigger of the menu item.

6 If you have chosen RunObject, you can define the object (form, report, codeunit) in the Object field. There is a lookup function available to help you select the object.

For other parametrized actions (for example, RunSystem) you have to set the parameters in the Property Sheet of the menu item (see below for details).

Adding Other Menu Items

In addition to lines that perform actions, menus can contain separators and lines that are submenus, that is, lines that open up another menu when you click them.

Separators A separator is a horizontal line in a menu that cannot be selected or perform any action. It helps you group items on a menu.

To add a separator to a menu, click the Separator button in the Menu Designer. The separator will be inserted after the currently selected line.

Submenus and Menu Levels Menu items can be nested, that is, when you click a line on a menu, another menu can open.

Submenus are defined in the Menu Designer. When an item is selected, you can indent it by clicking the right-arrow button. An indented item becomes a menu item on a submenu. If you open the Property Sheet for a menu item, you will see that when first created, menu items have the MenuLevel property set to a default value of zero.

As items are indented, the MenuLevel is set to 1, 2, 3 and so forth – one level for each click on the indentation button (you can cancel indentation by clicking the left-arrow button – each click cancels one level of indentation).

Key Entered as

Function keys F1, F2, F3, ...

Control, Alt, Shift CTRL, ALT, SHIFT

Other keys A, B, C, ... (these keys must be part of a key combination with CTRL or ALT).

Key combinations For example: CTRL+A, SHIFT+F2

8.5 Designing Menu Buttons

There are a few logical rules you must follow when creating submenus:

· If there are any items at all in a menu, there must be at least one item with MenuLevel 0 (zero).

· Each MenuLevel can be at most one higher than the preceding level in the list.

· If a higher MenuLevel follows a lower one (for example, 1 follows 0), the menu item with the MenuLevel 0 becomes a submenu, and the item with MenuLevel 1 becomes an item on this submenu. A menu line that is a submenu cannot have any action associated with it.

· There can be up to 10 menu levels (numbered from 0 to 9).

· If the MenuLevel reverts to lower numbers (less indentation), menu items will from then on become items in the previous menu at the level indicated by the

MenuLevel.

· Separators cannot be submenus and separators have to separate items at the same level, that is, you cannot put a separator as the first or last (or only) item in a menu or submenu.

Check Marks on Menu Items

Menus in Windows programs habitually employ a special feature: for menu items that act as toggles, the on/off state is indicated by the presence or the absence of a check mark next to the item in the menu.

The SourceExpr property of a menu item is used for controlling whether a check mark is displayed or not. Initially, the SourceExpr property is undefined. You can define it to a valid C/AL expression that evaluates to a boolean. The check mark appears when the value is TRUE.

You can see how this feature can be used in C/SIDE itself. In the Format menu, the Snap to Grid menu item is a typical example: it can either be on or off. When it is On, the check mark is displayed.

In document Navision Bible (Page 164-168)