How to Add Right Click Menu to an Item in C#
Muhammad Zeeshan
Feb 02, 2024
Csharp
Csharp GUI
This article will discuss adding a right-click menu to an item in a C# windows form.
Use ContextMenuStrip in C#
Follow the below steps to add a ContextMenuStrip into windows form and to add its item.
-
Open Visual Studio and create or open an existing
Windows Formproject. -
Go to
View > ToolBoxand enterContextMenuStripin search of ToolBox. -
Double click on
ContextMenuStripin ToolBox. -
It will add
ContextMenuStripon your form, as shown below.
-
Now, right-click on the
ContextMenuStripand click on the properties.
-
In the right-down properties panel, find
Itemsand click on the three-dot option.
-
Now, click the
Addbutton to add items, as I added three items below.
-
Create items
Eventsby double-clicking on each item.
-
Right click on
Windows form>propertiesand setContextMenuStripproperty ascontextMenuStrip1.
-
After creating events where you’ll write your logic, I’ll leave it blank so you can write your code here.
private void toolStripMenuItem1_Click(object sender, EventArgs e) {} private void toolStripMenuItem2_Click(object sender, EventArgs e) {} private void exitToolStripMenuItem_Click(object sender, EventArgs e) {}
Window Form Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RightClickItemByZeeshan {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {}
private void toolStripMenuItem1_Click(object sender, EventArgs e) {}
private void toolStripMenuItem2_Click(object sender, EventArgs e) {}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
Application.Exit();
}
}
}
Output:

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Muhammad Zeeshan
I have been working as a Flutter app developer for a year now. Firebase and SQLite have been crucial in the development of my android apps. I have experience with C#, Windows Form Based C#, C, Java, PHP on WampServer, and HTML/CSS on MYSQL, and I have authored articles on their theory and issue solving. I'm a senior in an undergraduate program for a bachelor's degree in Information Technology.
LinkedIn