Menus in C#

Menus provide groups of related commands for Windows applications.
commands depend on the program, some—such as Open and Saveare common to many applications.
Menus are very important part of GUIs, because they organize commands of the GUI.

How to create Menus in C#

To create a menu, open the Toolbox and drag a MenuStrip control onto the Form.
This creates a menu bar across the top of the Form (below the title bar) and places a MenuStrip.
icon in the component tray. To select the MenuStrip, click this icon.
Design mode to create and edit menus for your application.
Menus, like other controls, have properties and events, which can be accessed through the Properties window.
To add menu items to the menu, click the Type Here TextBox and type the menu item’s name.
This action adds an entry to the menu of type ToolStripMenuItem.


After you press the Enter key, the menu item name is added to the menu.
Then more Type Here TextBoxes appear, allowing you to add items underneath or to the side of the original menu item 




type an ampersand (&) before the character to be underlined.For example, to create the File menu item with the letter underlined, type &File.

To display an ampersand, type &&.
To add other shortcut keys (e.g., F9) for menu items, set the ShortcutKeys property of the appropriate ToolStripMenuItems.
To do ShortcutKeys , select the down arrow to the right of this property in the Properties window. In the window that appears, use the CheckBoxes and drop-down list to select the shortcut keys.
You can hide the shortcut keys by setting property Show ShortcutKeys to false, and you can modify how the shortcut keys are displayed in the menu item by modifying property ShortcutKeyDisplayString.


 You can remove a menu item by selecting it with the mouse and pressing the Delete key.
Menu items can be grouped logically by separator bars, which are inserted by right clicking the menu and selecting Insert > Separator or by typing “-” for the text of a menu item.
In addition to text, Visual Studio allows you to easily add TextBoxes and ComboBoxes (drop-down lists) as menu items.
Clicking the down arrow allows you to select the type of item to add


 

ToolStripMenuItem Properties


 •Checked: Indicates whether a menu item is checked. The default value is false, meaning that the menu item is unchecked.
CheckOnClick: Indicates that a menu item should appear checked or unchecked as it is clicked.
ShortcutKeyDisplayString: Specifies text that should appear beside a menu item for a shortcut key. If left blank, the key names are displayed. Otherwise, the text in this property is displayed for the shortcut key.
ShortcutKeys: Specifies the shortcut key for the menu item (e.g., -F9 is equivalent to clicking a specific item).
ShowShortcutKeys: Indicates whether a shortcut key is shown beside menu item text. The default is true, which displays the shortcut key.
TextSpecifies the menu item’s text. To create an Alt access shortcut, precede a character with & (e.g., &File to specify a menu named File with the letter F underlined).

No comments:

Post a Comment