Is there a way to tell what x/y coordinates were clicked in a FORMS application?
views:
652answers:
3
+2
A:
The MouseDown, MouseUp and MouseClick events all return the X and Y coordinates of the action.
heavyd
2009-06-10 13:15:19
+1
A:
Look at System.Windows.Forms.Control.MousePosition
(static property)
leppie
2009-06-10 13:15:20
Although the MousePosition does get the current mouse position, this can be unreliable when testing where a user clicks. The user can move the mouse before execution reaches your code where you check the property and you can get undesired results. The control events are much more reliable.
heavyd
2009-06-10 13:24:00
+2
A:
Take a look at the MouseEventArgs class. Specifically the GetPosition method. The example on MSDN is using onMouseMove, but you should be able to do the same with onMouseClick. Or just use the MouseClick event of the form.
E.g. using the MouseClick event:
On your form:
this.MouseClick += new MouseEventHandler(myForm_MouseClick);
void myForm_MouseClick(object sender, MouseEventArgs e)
{
int myX = e.X;
int myY = e.Y;
}
Jason Down
2009-06-10 13:16:27