如何使程序选中一个图片框与另一个控件相交? [英] How to make a program check a picture box intersects with another control?
问题描述
我想知道如何检查图片框是否与表单上的其他东西相交.我知道矩形:
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屋!