title: How do I properly apply padding to a group box control?
body: <p>I have a class that inherits a panel which I am adding a group box to. This group box contains for now a couple text boxes. I would like to have the text boxes centered horizontally and vertically within the group box by using the AutoSize property of the group box and the Padding property of the group box. Here is my attempt:</p>
  
  <pre><code>Imports System.Drawing
  
  Public Class pnlItemMstr_A_OSI
      Inherits Panel
  
      Public Sub New(ByRef ItemMstr_DS As DataSet, ByVal padding As Integer)
          MyBase.New()
  
          Dim drItemMstr As DataRow = ItemMstr_DS.Tables(0)(0)
          Dim txtHeight As Integer = 26
  
          ' article numbers
          Dim grpArtNum As New GroupBox
          Dim txtARTC_NUM_DOM_C As New TextBox
          Dim txtARTC_NUM_CAN_C As New TextBox
  
          With txtARTC_NUM_DOM_C
              .Text = drItemMstr("ARTC_NUM_DOM_C").ToString
              .Size = New Size(200, txtHeight)
              .Location = New Point(0, 0)
          End With
  
          With txtARTC_NUM_CAN_C
              .Text = drItemMstr("ARTC_NUM_CAN_C").ToString
              .Size = New Size(200, txtHeight)
              .Location = New Point(0, txtHeight)
          End With
  
          With grpArtNum
              grpArtNum.Text = "Article Number"
              grpArtNum.Padding = New Padding(padding)
              grpArtNum.Controls.Add(txtARTC_NUM_DOM_C)
              grpArtNum.Controls.Add(txtARTC_NUM_CAN_C)
          End With
  
          Me.Controls.Add(grpArtNum)
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>What I am ending up with is ugly and not what I would expect to happen, notice how the group box text is cut off:</p>
  
  <p><img src="https://i.stack.imgur.com/6Hoa8.png" alt="enter image description here"></p>
  
  <p>It seems the padding is not being applied properly, but I am sure I am just doing something wrong.</p>