Question

Is there a way to tell what x/y coordinates were clicked in a FORMS application?

Was it helpful?

Solution

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;
}

OTHER TIPS

The MouseDown, MouseUp and MouseClick events all return the X and Y coordinates of the action.

Look at System.Windows.Forms.Control.MousePosition (static property)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top