VB.NET collision between pictureboxes

懵懂的女人 提交于 2019-12-01 22:34:59

One way of doing it:

For Each PictureBox In Me.Controls
  If PictureBox IsNot PictureBox1 AndAlso PictureBox1.Bounds.IntersectsWith(PictureBox.Bounds) Then
     collision = True
     Exit For 'Exit when at least one collision found 
  Else : collision = False
  End If
Next

This would set collision to False if PictureBox is indeed PictureBox1. But note that you are overwriting the collision state in each loop, which not what you really want. You should exit the for loop when one collision is found (see my code). You may also change your code like this :

collision = False
For Each PictureBox In Me.Controls
  If PictureBox IsNot PictureBox1 AndAlso PictureBox1.Bounds.IntersectsWith(PictureBox.Bounds) Then
     collision = True
     Exit For
  End If
Next
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!