title: C# Collision Detection with PictureBox
body: <p>I have a program that adds a picturebox on click in the form, but I want to make sure that the picturebox doesn't overlap with any existing pictureboxes.</p>
  <p>Currently I have</p>
  <pre><code>PictureBox PB = new PictureBox();
  PB.Name = &quot;Table &quot; + number;
  PB.BackgroundImage = Image.FromFile(&quot;C:\\table.png&quot;);
  PB.Size = new Size(65,65);
  
  //x = x + 70;
  //y = y + 50;
  PB.Location = new Point(LocX, LocY);
  PB.MouseDoubleClick += new MouseEventHandler(this.PB_DoubleClick);
  foreach (Control picturebox in this.Controls)
  {
      if (PB.Bounds.IntersectsWith(picturebox.Bounds))
      {
          //Collision
      }
      else
      {
          this.Controls.Add(PB);
          
      }
  }
  </code></pre>
  <p>However the controls can still overlap behind one another see:</p>
  <p><img src="https://i.stack.imgur.com/2MePx.png" alt="Overlap example" /></p>
  <p>Clearly there is something I'm not doing in the code but I can't see what?</p>