views:

114

answers:

3

HI everyone,

I have a UserControl with a ContextMenuStrip attached to it.

I want to display ContextMenu base on which object was clicked on the surface of the control.

The issue is that, at the first launch, when I right-click on the control's surface, the contextMenuStrip doesn't show up!

I set breakpoint inside both contextMenuStrip_opening and contextMenuStrip_opened event but it seems that only contextMenuStrip_opening get fired.

What happened?

In what situation the contextMenuStrip doesn't show up?

Please help.

A: 

If the symptom is that the ContextMenuString does not show at all, I would bet that your code assigns true to the e.Cancel property in the Opening event handler.

If the menu shows, but the Opened event handler is not invoked my guess would be that the event handler for the Opened event is not attached for some reason.

Fredrik Mörk
A: 

did you assign all the controls ContextMenu property to the contextMenustrip that you have? or just you put it in the form?

Wael Dalloul
A: 

I didn't do such things as marking e.Cancel = true or not assigning the control. If it was, I had fought out by debugging.

I don't know why, but I add e.Cancel = false at the beginning of ContextMenuStrip_Opening event handler then it works fine.

thethanghn