C# - Detect PictureBox overlap

别来无恙 提交于 2019-12-24 13:34:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!