Windows Application - SPLessons

Win App Context Menu Strip

Home > Lesson > Chapter 17
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Win App Context Menu Strip

Windows Application Context Menustrip

shape Description

Context Menu strip is also called as popup menu or shortcut menu. The context menu is used to display a menu when one right click on the form or any other control.

shape Properties

Drag and drop the context menu strip onto the form. See the properties window related to context menu strip.
  • Name
    Set the appropriate name for your context menu strip.
  • Background and Foreground Colors
    One can change our Context Menu Strip appearance using these properties. One can also give the images for menu items.
  • Items
    Items property is used to give the menu items for context menu strip. One can also add the control as menu items to their context menu strip.

shape Example

A simple example on context menu strip. Follow the below steps to create a simple menu using context menu strip.

shape Step 1

After dropping the context menu strip on the form, click on the form and see the properties window related to form. In that, select the Context Menu property as ContextMenustrip1.

shape Step 2

Now, click on the Context Menu Strip and add the item as Exit. Double click on the Exit menu item and write the following code under the exit menu item generated event. [csharp]private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close();// Closes the current form }[/csharp]

shape Step 3

Press f5 to run the application. Then, the following window will be displayed.

shape Step 4

Now, right click on the form. Then, the menu which contains Exit menu item will be displayed as shown in the below figure.

shape Step 5

Click on the Exit. Then the window will be closed automatically. One can also set the shortcut keys for our menu items. This is the usage of the Context Menu Strip.