C# - 检测PictureBox重叠

时间:2015-11-21 17:53:43

标签: c# winforms picturebox

是否有可能检测到pictureBox是否与另一个pictureBox发生碰撞/重叠?对于模糊的问题表达感到抱歉。

2 个答案:

答案 0 :(得分:2)

要检查2个矩形是否重叠,您可以使用IntersectsWith

bool overlapped= pictureBox1.Bounds.IntersectsWith(pictureBox12.Bounds);

要查找交叉区域,您可以使用Rectangle.Intersect

Rectangle intersectionArea = Rectangle.Intersect(pictureBox1.Bounds, pictureBox2.Bounds);

答案 1 :(得分:1)

您可以使用Rectangle.Intersect 只需将两个PictureBox的Bounds提供给方法:

Rectangle unionRect = Rectangle.Intersect(pictureBox1.Bounds, pictureBox2.Bounds);
if (unionRect.IsEmpty) {
    // no intersecion
}