title: How do I center content in a Panel?
body: <p>I have a panel, inside which I am trying to center the controls. But apparently, panels don't like padding when they are docked to the edge of a control. Here is the current code for my panel:</p>
  
  <pre><code>buttonPanel = new Panel();
  buttonPanel.Width = 300;
  buttonPanel.Height = 50;
  buttonPanel.Dock = DockStyle.Bottom;
  buttonPanel.Padding = new Padding((this.ClientSize.Width - buttonPanel.Width) / 2, 0,
                                   (this.ClientSize.Width - buttonPanel.Width) / 2, 0);
  buttonPanel.BackColor = Color.Transparent;
  this.Controls.Add(buttonPanel);
  </code></pre>
  
  <p>I have a single button placed inside the panel. What I would expect with the above code, is that the control is placed nicely to the left of a 300 wide "rectangle" centered in the panel. But the button is placed on the very left, as if the padding is ignored:</p>
  
  <p><img src="https://i.stack.imgur.com/Aj9lO.png" alt="enter image description here"></p>
  
  <p>How can I center a collection of buttons to the center of my form?</p>