X/Y Coordinates of Click on an Image in a Windows Forms Application (.net)

我的梦境 提交于 2019-12-10 21:06:57

问题


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


回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/975468/x-y-coordinates-of-click-on-an-image-in-a-windows-forms-application-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!