如何使程序选中一个图片框与另一个控件相交? [英] How to make a program check a picture box intersects with another control?

查看:80
本文介绍了如何使程序选中一个图片框与另一个控件相交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何检查图片框是否与表单上的其他东西相交.我知道矩形:

I was wondering how I could check if a picturebox intersects with another thing on the form. I know for a rectangle its:

if (rectangle.IntersectsWith(otherRectangle))

但是(我知道,不可能)我想做上面的事情:

but (i know, not possible) i want to do like the above:

if (pictureBox1.IntersectsWith(pictureBox2))

有人知道检查的好方法吗?另外,我正在制作一个游戏,您可以在其中用箭头键移动图片框1,并随着空间跳动.谢谢!

Anyone know a good way to check? Also, im making a game in which you can move the picture box 1 with arrows keys, and jump with space. Thanks!

推荐答案

如果两个控件是相同表单或容器的子控件,则可以通过获取它们的

If two controls are children of the same form or container, then you can check whether the controls overlap by getting their Bounds and calling IntersectsWith:

if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds))

DisplayRectangle 是错误的属性;对于PictureBox,它返回(0,0,Width,Height),因此IntersectsWith如果Width和Height不为零,则始终返回true.

DisplayRectangle is the wrong property to access; for a PictureBox, it returns (0, 0, Width, Height), so IntersectsWith will always return true if Width and Height are nonzero.

这篇关于如何使程序选中一个图片框与另一个控件相交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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