获取已经点击的图片框的位置 [英] get the position of picturebox that has been clicked

查看:163
本文介绍了获取已经点击的图片框的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得已经被鼠标点击的picturebox的位置,但我不知道如何?
我的意思是picturebox的位置,而不是图片框的形式。
谢谢。

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.

推荐答案

MUGAN的关闭。你从MouseEventArgs得到的点是鼠标的屏幕点,其中0,0是整个显示器或桌面的左上角(但是你想想它)。要将其转换为PictureBox控件中的客户端点,其中0,0是该PictureBox的左上角,您需要使用Control.PointToClient()方法:

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

这篇关于获取已经点击的图片框的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆