views:

442

answers:

3

I am writing an app where the user should be able to alter the action of a button.

The user should right-click a button, and choose an option from a pop-up context menu. Once the choice has been made the button will perform a different action when the user uses a normal click.

I've already gotten the "Click" event working for a normal button click, however the "MouseClick" event handler isn't working correctly.

The "MouseClick" event gets activated on regular left-clicks, but never get's called for right-click.

Is there some default event handling being performed that is ignoring that right-click?

+2  A: 

If you want to display a context menu with actions to choose from it should be enough to assign a ContextMenuStrip to the ContextMenuStrip property. There is usually no need to manually handle the mouse events for that.

Fredrik Mörk
another SO post might be of some use: http://stackoverflow.com/questions/1044883/custom-user-control-in-c-right-click-menu-to-copy-text-java-developer-learnin
northpole
Thanks. I'll use this method. As a side-note, I did just find that the "MouseUp" event was the one I should have been looking at.
Tim Rupe
@birdlips: the memory is short, but on the other hand it was nearly 20 days ago :o)
Fredrik Mörk
+3  A: 

I'm sorry to say that this would be a serious UI blooper. Perhaps it would make more sense to add a small combobox next to the button.

Perhaps something like this?
http://www.codeproject.com/KB/buttons/SplitButton.aspx

Zyphrax
I agree, very non-standard and confusing. Poor design IMO.
Ed Swangren
@Ed - Well, my idea is actually very much like the solution posted in Zyphrax's link, so I don't think it's so terribly non-standard and confusing. However, the linked solution is a little more obvious and elegant than mine, so I'll probably go that direction if it makes sense in future applications.
Tim Rupe
+1  A: 

In Button (and certain other controls), the MouseClick event is only fired for the left button. Refer to MSDN.

If you want to know about the right button, respond to the MouseUp event--though as other posters have pointed out, this isn't a great UI idiom.

Ben M