title: How to get an object to center in a form
body: <p>I'm trying to simply center a panel in a form. I do this by using the simple formula of <code>Object Location = (Container Width - Object Width) / 2</code>. That's a simple mathematical way of moving an object to the center of its container (x-axis).</p>
  
  <p>However, it isn't working properly. It's putting probably about 10 pixels of extra space on the left side and I can't figure out why. If you reduce the size of the form enough, the panel touches the right side of the form, but is still about ten pixels away from the left side.</p>
  
  <p>I've checked to make sure that any margin or padding properties are set to 0, but with no luck.</p>
  
  <p>Does anybody know why this is happening and how to fix it?</p>
  
  <p>Here is my exact code:</p>
  
  <pre><code>Private Sub Form_Loaded(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      'Center Object
      pnlRadios.Location = New Point((Me.Width - pnlRadios.Width) / 2, 5)
  End Sub
  </code></pre>
  
  <p><strong>Update:</strong> I also tried: </p>
  
  <p><code>pnlRadios.Location = New Point(Me.Width / 2 - pnlRadios.Width /2 , 5)</code> </p>
  
  <p>and </p>
  
  <p><code>pnlRadios.Left = Me.Width / 2 - pnlRadios.Width / 2</code></p>
  
  <p>and got the exact same results with every attempt.</p>
  
  <p><strong>Update 2:</strong> I was able to do a manual workaround by adding <code>- 10</code> to the formula. It's centered now but it feels like I cheated and I still don't know why I had to do that in the first place, I can't figure out why there's some sort of padding on the left side.</p>