![]() The same name is also used in naming the Click event handler of the item. Each menu item has a name, which allows you to access its properties from within your code. The leftmost items in Table 5.4 are the names of the first-level menus (File and Edit) the captions that are indented in the table are the commands on these two menus. Table 5.4 – The Captions and Names of the File and Edit Menus Caption You can also insert a standard menu with the Insert Standard Items command of the MenuStrip object’s context menu. Table 5.4 shows the captions (property Text) and names (property Name) for each menu and each command. Fill the Edit menu with the usual editing commands. Press Enter and you’ll switch to the first item of the Edit menu. In the new item that appears next to the File item on the control, enter the string Edit. To add the Edit menu, select the MenuStrip icon to activate the visual menu editor and then click the File item. All the temporary items (the ones with the Type Here caption) will disappear, and the menu will be finalized on the form. The last two options, however, allow you to build elaborate menus, reminiscent of the Office menus.Įnter the items of the File menu - New, Open, Save, SaveAs, and Exit - and then click somewhere on the form. In this chapter, I’ll focus on menu items, which are by far the most common elements on a menu. This item can be a MenuItem object, a separator, a ComboBox, or a TextBox. Click this button to select the type of item you’ll place on the menu. When you hover the pointer over a menu item, a drop-down button appears to the right of the item. To insert a separator, enter a hyphen (-) as the item’s caption. ![]() ![]() Press Enter to move to the next item vertically, and Tab to move to the next item horizontally. Depending on your action, another box will be added, in which you can type the caption of the next command. To enter another command in the main menu, press Tab. ![]() To add items under the File menu, press Enter. Do as the caption says: Click it and enter the first command’s caption, File, as seen in Figure 5.15. If you don’t see the first menu item on the form right away, select the MenuStrip control in the Components tray below the form. (You’ll find the MenuStrip control in the Menus & Toolbars tab of the Toolbox.) An instance of the MenuStrip control will be added to the form, and a single menu command will appear on your form. Let’s start by designing a simple menu, and I’ll show you how to manipulate the menu objects from within your code as we go along.ĭouble-click the MenuStrip icon in the Toolbox. Because each item in a menu is represented by a ToolStripMenuItem object, you can control the application’s menus from within your code by manipulating the properties of the ToolStripMenuItem objects. Depending on the needs of your application, you might want to enable and disable certain commands, add context menus to some of the controls on your form, and so on. In principle, that’s all there is to a menu: You specify its items (the menu’s commands) and then you program each command’s actions. You can design menus visually and then program their Click event handlers. The MenuStrip control is a variation of the Strip control, which is the base of menus, toolbars, and status bars. As you will see, the MenuStrip control and ToolStripMenuItem objects give you absolute control over the structure and appearance of the menus of your application. The items that make up the menu are ToolStripMenuItem objects. Menus can be attached only to forms, and they’re implemented through the MenuStrip control. You can turn the toolbars on and off, but not the menus. Many applications duplicate some or all of their menus in the form of toolbar icons, but the menu is a standard fixture of a form. Despite the visually rich interfaces of Windows applications and the many alternatives, menus are still the most popular means of organizing a large number of options. Even in the old days of character-based displays, menus were used to display methodically organized choices and guide the user through an application. Menus are among the most common and most characteristic elements of the Windows user interface.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |