views:

32

answers:

2

I am using an old ActiveX control in my C# Win App. it has a MouseUp event that its eventArgs is passing the X and Y of the point that we have clicked but for my scenario I am using its ItemClick event and its eventArgs does not have the info about X and Y. but I need to know them to show my pop-up... so is there a way I can find out what is the location of X and Y that user has right-clicked so I can pass it to my contextMenuStrip.Show method.

Thanks

+2  A: 

The Control class has a static readonly MousePosition property, this gives the mouse coordinates on the screen. You could use this to know where to position the ContextMenu.

From MSDN:

Control.MousePosition Property

Type: System.Drawing.Point

A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.

fletcher
+2  A: 

Cursor.Position will get you the current screen coordinates of the cursor. For most uses this is good enough, even though the mouse can potentially move between the click and the handler being called.

corvuscorax
thanks corvuscorax, both your answer and fletcher's worked for me. I marked his as "answer" just because it was posted earlier.
BDotA
+1 Both solutions return the coords of the mouse. It'd be wrong not to upvote
fletcher