* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
5.5 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Walkthrough: Providing Standard Menu Items to a Form | 03/30/2017 |
|
|
dac37d98-589e-4d6d-9673-6437e8943122 |
Walkthrough: Providing Standard Menu Items to a Form
You can provide a standard menu for your forms with the xref:System.Windows.Forms.MenuStrip control.
This walkthrough demonstrates how to use a xref:System.Windows.Forms.MenuStrip control to create a standard menu. The form also responds when a user selects a menu item. The following tasks are illustrated in this walkthrough:
-
Creating a Windows Forms project.
-
Creating a standard menu.
-
Creating a xref:System.Windows.Forms.StatusStrip control.
-
Handling menu item selection.
When you are finished, you will have a form with a standard menu that displays menu item selections in a xref:System.Windows.Forms.StatusStrip control.
To copy the code in this topic as a single listing, see How to: Provide Standard Menu Items to a Form.
Prerequisites
You'll need Visual Studio to complete this walkthrough.
Create the project
-
In Visual Studio, create a Windows application project called StandardMenuForm (File > New > Project > Visual C# or Visual Basic > Classic Desktop > Windows Forms Application).
-
In the Windows Forms Designer, select the form.
Create a standard menu
The Windows Forms Designer can automatically populate a xref:System.Windows.Forms.MenuStrip control with standard menu items.
-
From the Toolbox, drag a xref:System.Windows.Forms.MenuStrip control onto your form.
-
Click the xref:System.Windows.Forms.MenuStrip control's designer actions glyph (
) and select Insert Standard Items.The xref:System.Windows.Forms.MenuStrip control is populated with the standard menu items.
-
Click the File menu item to see its default menu items and corresponding icons.
Create a StatusStrip control
Use the xref:System.Windows.Forms.StatusStrip control to display status for your Windows Forms applications. In the current example, menu items selected by the user are displayed in a xref:System.Windows.Forms.StatusStrip control.
-
From the Toolbox, drag a xref:System.Windows.Forms.StatusStrip control onto your form.
The xref:System.Windows.Forms.StatusStrip control automatically docks to the bottom of the form.
-
Click the xref:System.Windows.Forms.StatusStrip control's drop-down button and select StatusLabel to add a xref:System.Windows.Forms.ToolStripStatusLabel control to the xref:System.Windows.Forms.StatusStrip control.
Handle item selection
Handle the xref:System.Windows.Forms.ToolStripDropDownItem.DropDownItemClicked event to respond when the user selects a menu item.
-
Click the File menu item that you created in the Creating a Standard Menu section.
-
In the Properties window, click Events.
-
Double-click the xref:System.Windows.Forms.ToolStripDropDownItem.DropDownItemClicked event.
The Windows Forms Designer generates an event handler for the xref:System.Windows.Forms.ToolStripDropDownItem.DropDownItemClicked event.
-
Insert the following code into the event handler.
[!code-csharpSystem.Windows.Forms.ToolStrip.StandardMenu#3] [!code-vbSystem.Windows.Forms.ToolStrip.StandardMenu#3]
-
Insert the
UpdateStatusutility method definition into the form.[!code-csharpSystem.Windows.Forms.ToolStrip.StandardMenu#2] [!code-vbSystem.Windows.Forms.ToolStrip.StandardMenu#2]
Checkpoint -test your form
-
Press F5 to compile and run your form.
-
Click the File menu item to open the menu.
-
On the File menu, click one of the items to select it.
The xref:System.Windows.Forms.StatusStrip control displays the selected item.
Next steps
In this walkthrough, you have created a form with a standard menu. You can use the xref:System.Windows.Forms.ToolStrip family of controls for many other purposes:
-
Create shortcut menus for your controls with xref:System.Windows.Forms.ContextMenuStrip. For more information, see ContextMenu Component Overview.
-
Create a multiple document interface (MDI) form with docking xref:System.Windows.Forms.ToolStrip controls. For more information, see Walkthrough: Creating an MDI Form with Menu Merging and ToolStrip Controls.
-
Give your xref:System.Windows.Forms.ToolStrip controls a professional appearance. For more information, see How to: Set the ToolStrip Renderer for an Application.