views:

532

answers:

1

I am adding a label to a form dynamically, then dynamically adding a ContextMenuStrip control. Whether I use the label.ContextMenuStrip property to connect them, or add the event handler to the label manually to have it respond to the right-click and show the context menu, I get odd behavior:

1) The menu does not appear next to the mouse pointer, it is offset down and to the right. It appears that it is related to the position of the label in it's parent control (a picture control), rather than the form.

2) The menu does not disappear when I click on something other than the menu.

Any ideas what I am missing here?

Thanks, Andy

+1  A: 

I worked it out. First off, I was adding the control to the label control collection, changing it to the the form collection corrected the positioning problem. I never did figure out why the menu would not close.

Ultimately I restructured things by adding a static instance of the menu to the form, then just connected the label.ContextMenuStrip property to that stastic instance. All is well with that approach.

I used the tag of the label control to identify it to the click event handler.