简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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