Context menu needs to be popped from many controls

J

Just Me

I have a usercontrol on which I have, say, five controls.

I want a context menu to popup when the mouse is clicked anywhere on the
userconttrol.

The same context menu.

What I've done in the past is to put code in each control's mouseup event.

Is that the way to go or is there a better way?



Thanks
 
C

Chris, Master of All Things Insignificant

Make a single sub that you call from each mouseclick event. Or if the
control's mouseclick events have the same function prototype (which they
probably do) you can just add handlers onto the same function

Sub Generic_MouseCick(Sender as object, .......) handles
Control1.MouseClick, Control2.MouseClick
'Popup
End sub

You could also use the Addhandler function to do it instead of the handles
keyword.

Chris
 
J

Just Me

Chris said:
Make a single sub that you call from each mouseclick event. Or if the
control's mouseclick events have the same function prototype (which they
probably do) you can just add handlers onto the same function

Sub Generic_MouseCick(Sender as object, .......) handles
Control1.MouseClick, Control2.MouseClick
'Popup
End sub

Good, Thanks a lot
 
H

Herfried K. Wagner [MVP]

Just Me said:
I have a usercontrol on which I have, say, five controls.

I want a context menu to popup when the mouse is clicked anywhere on the
userconttrol.

The same context menu.

What I've done in the past is to put code in each control's mouseup event.

Is that the way to go or is there a better way?

Yes, assigning it to the controls' 'ContextMenu' property. This will allow
the menu to popup when the context menu key is pressed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top