21

I want to make a right click menu for my winforms app. It will have the same two things in it no matter where it pops up. A little hunting and pecking leads me to the conclusion that winforsm either doesn't support this in a trivial way or has hidden it under some name I havn't guessed yet. I think I can make it work with the Click event and manually creating a menu in the right place, bla bla bla... Yuck, I can thing of a half dozon thing right now that I would get wrong the first time around. Someone has got to have a better way.

Am I missing some easy way to add this?

Is there some library/widget I can copy/paste in to handle the grunt work for me?

SteveCav
  • 6,649
  • 1
  • 50
  • 52
BCS
  • 75,627
  • 68
  • 187
  • 294

3 Answers3

28

Add a System.Windows.Forms.ContextMenuStrip item to the form, then set the form's ContextMenuStrip property.

MiffTheFox
  • 21,302
  • 14
  • 69
  • 94
4

Put a ContextMenuStrip on your form, design your menu, then set the ContextMenuStrip property on the form to the component created.

Majid
  • 13,853
  • 15
  • 77
  • 113
Michael Bray
  • 14,998
  • 7
  • 42
  • 68
3

After putting a ContextMenuStrip on your form, Add it to your Control (you can do it in Control's Properties) and then , use code like this for showing menu:

private void myTree_MouseClick(object sender, MouseEventArgs e)
{
     myTree.ContextMenu.Show(myTree, new Point(e.X, e.Y));
}

more on MSDN.

user3797758
  • 829
  • 1
  • 14
  • 28
Majid
  • 13,853
  • 15
  • 77
  • 113