8

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,

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SandhraPrakash
  • 442
  • 2
  • 6
  • 15

2 Answers2

2

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[]);
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
1
ContextMenu context = new ContextMenu();
context.Items.Add(new MenuItem().Header = "Add To Favorites");
benka
  • 4,732
  • 35
  • 47
  • 58
cerberus
  • 331
  • 2
  • 9
  • 1
    Please add a few words to your code. For users who a searching for answers is just a code not very helpful. – Hille Apr 18 '18 at 07:42