views:

40

answers:

2

Is it possible to check for a right-click on a menu item in .NET?

It appears that the framework doesn't expose it as an Event, but I've seen other applications (like Chrome and Firefox) which allow you to bring up a right-click context menu for a menu item. Presumably with a little event-loop magic you can do the same thing in .NET, right?

EDIT: I'm talking about desktop application programming, not ASP.NET.

A: 

In Winforms I'm unsure, I don't think so, the Click event is a generic EventHandler

In WPF, You can, the OnClick Event passes in a System.Windows.Input.MouseEventArgs object, which has properties on it like .MiddleButton .RightButton

For ASP.NET You need to use javascript to catch the right-click and submit a secret form, initiate a post-back, or use AJAX.

Aren
+1  A: 

It is an unnatural act. Menus are designed to automatically pop down when they lose the focus. The context menu will take the focus, end of menu. MenuStrip will fight you tooth and nail, I haven't seen it done.

Hans Passant
Agree. I find it weird to right click on a menu item.
Lex Li