10. Menu Components
77) Q: The menu is a common Windows user interface. Menus are an essential part of a program that can be applied in practice. In C ++ Builder, how does one implement menus?
A: C ++ Builder provides two menu components: MainMenu, and PopMenu.
The main menu component generates menu entries on the form. When the menu component is placed on the form, the menu is invisible. When you double-click it to open the menu editor and add a menu item, the menu bar appears at the top of the form. The menu bar at design time is exactly the same as the menu bar at runtime.
The following describes how to use the menu editor to design menus.
First, open the menu editor.
78) Q: When the sub-menu items in a menu item belong to different categories, it is necessary to Group sub-menu items using separation bars. How does the menu component implement this function?
A: select a separator between exit and save. Right-click the exit menu and select Insert from the pop-up menu, A blank menu item is inserted. set its Caption attribute to the minus sign.
79) Q: How do we set a hotkey for the menu item?
A: Each menu item has a ShortCut, which allows you to set a hotkey for this menu item. Now we add a hotkey for the menu item to open the file. Click this menu item and select attribute ShortCut cut. A drop-down menu is displayed, which includes a combination of a series of hot keys. Select Ctrl + O, and this hot key is assigned to the exit menu item.
80) Q: I am confused about the two concepts of shortcuts and hotkeys. Can you explain them to me?
A: Okay. In the same way as the hotkeys, they are all accessed through the keyboard.
A menu item can have both shortcut keys and hotkeys. The shortcut key is usually a letter, and the hotkey is usually a combination key. In addition, they are activated differently. For example, if a sub-menu item has a shortcut key O and a hot key Ctrl + O, you can directly activate this sub-menu item by using the hot key, to use the shortcut key, you must first select the menu item on the top of the sub-menu item, and then press the shortcut key to activate this sub-menu item.
81) Q: The menu you have explained is only at the menu item level and sub-menu level. What should I do if I want the sub-menu to have my own sub-menu?
A: This nested menu item is actually a cascading menu. Here, we add a sub-menu item to the color menu item, select the color menu, right-click, and select the Create Submenu command from the shortcut menu that appears, in this case, an arrow pointing to the right appears in the sub-menu item, and a cascading menu is generated.
You can also right-click Ctrl +.
82) Q: There are check marks next to many menu items. Does the menu editor provide this function?
A: The check mark is the check mark that appears before the title of the menu item. The check mark is often used for menu items in some state settings. When it is in this State, a check mark is displayed. Otherwise, the check mark disappears.
Now, we can set a check mark for the rewinding menu item, and change its attribute Checked to True in the object editor, so that the check mark will be displayed for this menu item. To cancel the check mark, you can set the Checked attribute to False again.
Select the MainMenu component from the Standard tab on the component template and place it on the form. Right-click the Menu component and choose Menu Designer from the context Menu. You can also double-click the menu component to open the menu editor.
The highlighted box is a blank menu item.
Next, add a menu item.
Select this menu item, and the properties of this menu item will appear in the object editor.
In the Caption attribute of the menu item, enter "File (& File)", where "& F" can generate a shortcut key so that users can operate on the keyboard, and the underline appears below F (NOTE: For system reasons, "&" must be entered in English ). When we enter the title and press the Enter key, C ++ Buildr automatically assigns a name to this menu item, whose name is N1. If you are not satisfied with the Name, you can modify the Name attribute.
After a menu item is added, a blank sub-menu item is automatically displayed, waiting for you to enter.
Now the input focus in the menu editor is moved to the blank sub-menu item, and the object editor displays the properties of this Sub-menu item. You can enter the title "Open (& Open)" of the sub-menu item in the Caption attribute and press Enter. The menu Editor opens a new sub-menu item and moves the input focus to this sub-menu item. In this way, you can add a series of sub-menus to the menu items.
Add the exit menu in the same way.
To edit the next menu item, you can click the dotted box on the right of the menu item "file", which indicates a blank menu item.
83) Q: I sometimes want to design a group of mutually exclusive menu items, that is, single-choice menu items. What should I do?
A: To make a group of menu items a single menu item, you must meet the following conditions.
First, these menus must be in the same drop-down menu.
Second, their RadioItem attributes must be set to True.
Finally, their GroupIndex attributes must be the same.
A dot mark is displayed before the only selected menu item in this group.
84) Q: How can I Invalidate a menu item?
A: You only need to set the Enabled attribute of the menu item to False to invalidate the menu item. In this case, the menu item is gray. You can set the Enabled attribute of the menu item at design time and runtime.
85) Q: What are some common menu events?
A: There is only one event OnClick in the menu item. In actual editing, this event must be responded.
86) Q: Generally, a shortcut menu is provided out of the main menu. Just like C ++ Builder, you can right-click the form to open a pop-up menu at any time. How does C ++ Builder implement the pop-up menu?
A: A pop-up menu is also called a shortcut menu. The difference between a pop-up menu and a main menu is that the main menu is fixed, while a pop-up menu is active. The main menu has multiple menu items, and there is only one set of pop-up menus. The pop-up menu is basically the same as the main menu, and is also completed using the menu editor.