在点击阅读图片框鼠标坐标
我有一个图片框已加载的图片,我想读的位置(如X,Y的图片框中),当我点击图片;这可能吗 ?甚至,我可以读取这些坐标(点),当我鼠标?
I have a Picture Box with a picture loaded and I want to read the location (as in x,y inside the Picture Box) when I click the image; is this possible ? Even more, can i read these coordinates (Points) when i mouse over ?
我知道我必须使用特定的事件(鼠标单击和鼠标移过),但不知道如何读的地方,鼠标指针恰好是坐标。
I know i have to use the events given (Mouse Click and Mouse Over) but don't know how to read the coordinates where the mouse pointer happens to be.
虽然其他的答案是正确的,让我我点添加到它。
你指出,你需要挂钩鼠标点击
或鼠标悬停
事件作此用途。其实这是没有必要挂钩这些事件让坐标
,你可以在短短坐标 C>点击事件本身。
Though other answers are correct let me add my point to it.
You've pointed that you need to hook up MouseClick
or MouseOver
events for this purpose. Actually that is no need to hook those events to get Coordinates
, you can get the Coordinates
in just Click
event itself.
private void pictureBox1_Click(object sender, EventArgs e)
{
MouseEventArgs me = (MouseEventArgs)e;
Point coordinates = me.Location;
}
上面的代码工作,因为Click事件的电子
参数包 MouseEventArgs
你可以只投它,利用它。
The above code works since Click event's e
argument wraps MouseEventArgs
you can just cast it and make use of it.