开发者

get the position of picturebox that has been clicked

开发者 https://www.devze.com 2023-02-15 09:07 出处:网络
I want to get the position of the picturebox that has been cliked by the mouse,but i don\'t know how??

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开发者_Go百科.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号