问题
Is it possible to detect if a pictureBox is colliding with/overlapping with another pictureBox? Sorry for the vague question formulation.
回答1:
To check if 2 rectangles overlapped you can use IntersectsWith:
bool overlapped= pictureBox1.Bounds.IntersectsWith(pictureBox12.Bounds);
To find the intersection area you can use Rectangle.Intersect:
Rectangle intersectionArea = Rectangle.Intersect(pictureBox1.Bounds, pictureBox2.Bounds);
回答2:
You can use Rectangle.Intersect.
Just give Bounds
of both PictureBoxes to the method:
Rectangle unionRect = Rectangle.Intersect(pictureBox1.Bounds, pictureBox2.Bounds);
if (unionRect.IsEmpty) {
// no intersecion
}
来源:https://stackoverflow.com/questions/33846662/c-sharp-detect-picturebox-overlap