title: Positioning Controls in the .Net GroupBox
body: <p>Normally, I write forms that are resizeable (gracefully) using the method below.</p>
  
  <pre><code>using System.Drawing;
  using System.Windows.Forms;
  namespace silly
  {
      public class Form1 : Form
      {
          private GroupBox g;
          private Button b1, b2;
          public Form1()
          {
              Init();
          }
          private void Init()
          {
              //create and add controls.
              this.Controls.Add(g = new GroupBox());
              g.Controls.AddRange(new Control[] { 
                      b1 = new Button(),
                      b2 = new Button()});
  
  
              g.Text = "group";
              b1.Text = "b1";
              b2.Text = "b2!";
  
  
              b1.AutoSize = b2.AutoSize = true;
  
  
              g.Resize += new System.EventHandler(g_Resize);
  
          }
  
          private void g_Resize(object sender, System.EventArgs e)
          {
              b1.Size = b2.Size = new Size(g.ClientSize.Width, g.ClientSize.Height/2);
              b1.Location = Point.Empty;
              b2.Location = new Point(b1.Left, b1.Bottom);
          }
          protected override void OnResize(System.EventArgs e)
          {
              g.Size = this.ClientSize;
              g.Location = Point.Empty;
          }
      }
  }
  </code></pre>
  
  <p>However, you will quickly notice, that the <code>g.ClientSize</code> property doesn't work like the <code>Form.ClientSize</code> property. What I have been doing is adding a <code>Point</code> with the values:</p>
  
  <pre><code>private readonly static Point grp_zero = new Point(10, 20);
  </code></pre>
  
  <p>to help properly place components.  Using this value, I can refactor the <code>g_Resize</code> method with:</p>
  
  <pre><code>b1.Size = b2.Size = new Size(g.ClientSize.Width - grp_zero.X * 2, 
      g.ClientSize.Height/2 - grp_zero.X - grp_zero.Y);
  b1.Location = grp_zero;
  b2.Location = new Point(b1.Left, b1.Bottom);
  </code></pre>
  
  <p>with fairly good results.  However, if at the end of <code>Init();</code>, the following code is found:</p>
  
  <pre><code>            g.Font = new Font(g.Font.FontFamily, 28);
  </code></pre>
  
  <p>or something like it, <code>grp_zero</code> deserves to be resized.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a good workaround against this madness?  What do you do?</p>
  
  <p>I tried <code>Dock</code> and <code>Anchor</code>, but I can't seem to get them to make the buttons fill up the <code>GroupBox</code> client area.  The effect I'm after here is for each button to fill his half of the client area.</p>
  
  <p>Thanks in advance.</p>