C ++ Builder first-study and answer (10)

zhaozj2021-02-16  42

10. Menu components

77) Q: The menu is a user interface commonly used by Windows. For a program that can actually apply, the menu is an indispensable component. How do I implement a menu in C Builder?

A: C Builder provides us with two menu components: one is the main menu component mainmenu; the other is the pop-up menu PopMenu component.

The role of the main menu component is to generate a menu bar on the form. When the menu component is just put on the form, the menu is invisible. When you double-click it to open the menu editor and add the menu item, the menu bar appears at the top of the form. The menu strip when design is exactly the same as the runtime menu bar.

Below we introduce the process of using the menu editor for menu design.

First open the menu editor

Select the mainMenu component from the Standard tab on the component template and placed onto the form. Then, right-click the menu component and select Menu Designer in the pop-up menu. Of course, you can also double-click the menu component to open the menu editor.

The brightened frame that is highlighted is a blank menu item.

Then you want to add a menu item

Select this menu item, this time the property of this menu item will appear in the object editor.

We entered "& File" in the capensient attribute of menu items, where "& f" can generate a shortcut, so that the user can operate through the keyboard, and the next line appears below (note: because it is a system reason, " & "Be sure to enter in English). When we enter the title and press Enter key, C BuildR will automatically assign a name to this menu item, the name here is N1. If you are not satisfied with this name, you can modify the Name property.

A blank submenu item will automatically appear after adding a single item.

Now the input focus in the menu editor is moved on this blank menu item, and the object editor will display the properties of this submenu item. You can enter the title item of the submenu item in the CAPTION property, then press Enter. The menu editor opens a new submenu and move the input focus to this submenu item. In this way, you can add a series of submeni to the menu item.

The same method adds an exit menu.

To start editing the next menu item, you can use the mouse to click the dotted box on the right side of the menu item "File", which represents a blank menu item.

78) Q: When the submenu item in the menu item belongs to a different category, it is necessary to use the separator to group the submenu item, how does the menu component implement this function?

A: We add the selection partition in the middle of the two menu items. On the exit menu item, click the right mouse button. From the pop-up menu, select Insert, at this time, a blank menu item is inserted, put it Caption property Set to "-" This minus sign is OK.

79) Q: So, how do we set a hotkey to menu items?

A: Each menu item has an attribute shortcut, and this property can be set to the menu item. Now let's add a hotkey to the open file menu item. Click this menu item, select the properties shortcut, a drop-down menu, which includes a combination of a series of hotkeys. Select Ctrl O, which is given to the exit menu item in this hotkey.

80) Q: The shortcuts and hot keys I have already cave it, can you explain it?

A: Ok, shortcuts and hot keys are the same, they are all accessed through the keyboard.

A menu item can have a shortcut and hotkey at the same time. The so-called shortcuts is usually just a letter, and the hotkey is usually a key combination. In addition, their activation is different. For example, a submenu item has a shortcut key O and a hotkey Ctrl O, then use the hotkey to directly activate this submenu item, and use shortcuts you must first select the submenu first The menu item on the item, then press the shortcut to activate this submenu item. 81) Q: You explain that there are only menu items and submenu now, if I want the submenu, what should I do?

A: This nesting menu item is actually a cascade menu. Here, we add a submenu item to the color menu item, select the color menu, click the right mouse button, select the CREATE SUBMENU command in the pop-up shortcut menu, at which time a point to the right arrow will appear in the submenu item, and also generate A cascade menu.

Of course, you can also use the CTRL direction key to right.

82) Q: There are several menu items with check mark. Does the menu editor provide this feature?

A: The check mark is the tip number that appears in front of the title item title. The check mark is often used in some menu items set, and the check mark will appear when in this state, otherwise the check mark disappears.

Now, we give the round menu item setting check mark, change its property Checked to TRUE in the object editor, so this menu item will display the check mark. To cancel the check mark, you can set the checkage attribute to false.

83) Q: I sometimes want to design a group of mutually exclusive menu items, which is just a single choice item, what should I do?

A: To make a set of menu items a single selection menu item, you must meet a few conditions.

First, this group of men must be in the same drop-down menu.

Second, their RadioItem properties must be set to TRUE.

Finally, their GroupIndex properties must be the same.

A dot mark will be displayed in front of this uniquely selected menu item.

84) Q: How do I get the menu item?

A: Just set the enabled property of the menu item to false, you can make the menu item fail, and the menu item is gray. When designing and running, you can set the enabled attribute of the menu item.

85) Q: What is commonly used in menu items?

A: The menu item has only one event onclick, and this event in actual editing is a must respond.

86) Q: We typically provide a shortcut menu outside the main menu, just like C Builder, click Right-click in the form to open a pop-up menu at any time. How does C Builder implement pop-up menu?

answer:

The pop-up menu is sometimes referred to as a shortcut menu. The difference between the pop-up menu and the main menu is that the main menu is fixed, and the pop-up menu is active; the main menu has multiple group menu items, and only one pop-up menu is only one set. The design method of the pop-up menu is basically the same as the main menu, but also using the menu editor.

转载请注明原文地址:https://www.9cbs.com/read-26008.html

New Post(0)