简体   繁体   English

如何轻松检测矩形/图像内部的单击?

[英]How to easily detect click inside of rectangle/image?

When I draw an image, I know I could find out whether the user clicks on it by comparing X,Y of mouse with position and size of that image. 当我绘制图像时,我知道可以通过将鼠标的X,Y与该图像的位置和大小进行比较来确定用户是否单击了它。 However is there a quicker way? 但是,有没有更快的方法? I know for two rectangles there is an intersect methods. 我知道对于两个矩形有一个相交方法。 Thanks 谢谢

Ultimately, the same thing has to happen. 最终,同一件事必须发生。 The point coordinates need to be tested against the rectangle coordinates. 需要针对矩形坐标测试点坐标。 But if you already have Rectangle r and Point p, you can do if (r.Contains(p)) . 但是,如果您已经具有Rectangle r和Point p,则可以执行if (r.Contains(p))

不确定是否可行(因为我不清楚您要完成的工作),但是也许您可以在要单击的区域后面放置一个按钮,然后为该按钮分配图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM