Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a contextMenu programmatically in C#(VS 2008)?

I'm using VS 2008, and I would like to add a contextMenu (definitely not ContextMenuStrip!!) to my application. There is no contextMenu (!!) in the toolbox. So how can I add it programmatically to my code?

Thanks In Advance,

like image 926
SandhraPrakash Avatar asked Jun 13 '13 06:06

SandhraPrakash


2 Answers

I assume you use Winforms, you can initialize ContextMenu class in your code. It has a 2 constructor which you can pass MenuItem as a parameter.

ContextMenu cm = new ContextMenu();

or

ContextMenu cm1 = new ContextMenu(new MenuItem[]);
like image 193
Soner Gönül Avatar answered Oct 19 '22 20:10

Soner Gönül


ContextMenu context = new ContextMenu();
context.Items.Add(new MenuItem().Header = "Add To Favorites");
like image 39
cerberus Avatar answered Oct 19 '22 19:10

cerberus