![]() You can also select to display text only, images only, or text and images for each menu item with the DisplayStyle property.Here is an example using your code where it adds a handler to each DropDownItem and in the event handler sub it gets the name of the DropDownItem that was clicked. The TextImageRelation property allows you to specify the relative positions of the text and the image. You can add all the images and icons you might need in a project to the same resource file and reuse them at will. Notice that all the images you use on your form are stored as resources of the project. A dialog box will appear, in which you can select the appropriate resource. To add an image to a menu item, locate the Image property and click the ellipsis button. You can also set their font, set the alignment and orientation of the text, and specify an image to be displayed along with the text. As you add new items, you can set their Text and Name properties on the right pane of the editor. To insert an item at a different location, add it to the menu and then use the arrow buttons to move it up or down. The Add button adds to the menu an item of the type specified in the combo box next to it (a menu item, combo box, or text box). This isn’t a visual editor, but you can set all the properties of each menu item without having to switch to the Properties window.įigure 5.16 – Editing a menu with the Items Collection Editor The most convenient method of editing a menu is to use the Items Collection Editor window, which is shown in Figure 5.16. To view the properties of a menu item, right-click it and select Properties from the context menu. To do so, change the Name property in the Properties window. ![]() You’ll probably want to change the default names to something less redundant. The default names of the menu items you add visually to the application’s menu are based on the item’s caption followed by the suffix ToolStripMenuItem (FileToolStripMenuItem, NewToolStripMenuItem, and so on). 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. 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |