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.
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.
Example
A simple example on context menu strip. Follow the below steps to create a simple menu using context menu strip.
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.
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]
Step 3
Press f5 to run the application. Then, the following window will be displayed.
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.
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.