get the position of picturebox that has been clicked

霸气de小男生 提交于 2019-12-23 02:18:21

问题


I want to get the position of the picturebox that has been cliked by the mouse,but i don't know how?? I mean the position of picturebox not the form that the picturebox on it. thanks.


回答1:


MUGAN's close. The Point you'll get from MouseEventArgs is the "screen" point of the mouse, where 0,0 is the top left of the entire monitor or desktop (however you want to think of it). To convert that to a "client" point within the PictureBox control, where 0,0 is the top left of that PictureBox, you'll need to use the Control.PointToClient() method:

private void pb_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    Point mouseDownLocation = (Control)sender.PointToClient(new Point(e.X, e.Y));
    //here goes your if condition ...
}



回答2:


private void pb_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    Point mouseDownLocation = new Point(e.X, e.Y);
    //here goes your if condition ...
}


来源:https://stackoverflow.com/questions/5235967/get-the-position-of-picturebox-that-has-been-clicked

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