title: Align dynamically added controls horizontally and vertically within a control in c# winforms
body: <p>I have this program that dynamically adds pictureboxes referring to the number of president in the database. How do i put them inside the groupbox and align the pictureboxes inside the groupbox? And the groupbox should stretch if the pictureboxes are many.</p>
  
  <p>I have this codes now :</p>
  
  <pre><code>    private void Form1_Load(object sender, EventArgs e)
      {
          conn.Open();
  
          try
          {
              cmd = new SqlCommand("SELECT COUNT(Position) FROM TableVote WHERE Position='" + "President" + "'", conn);
              Int32 PresCount = (Int32)cmd.ExecuteScalar();
  
              TxtPresCount.Text = PresCount.ToString();
  
              for (int i = 0; i &lt; PresCount; ++i)
              {
                  GroupBox PresGB = new GroupBox();
                  {
                      PresGB.Size = new Size(491, 152);
                      PresGB.Location = new Point(12, 12);
                      PresGB.Text = "President";
                      this.Controls.Add(PresGB);
                      PresGB.SendToBack();
  
                      PictureBox PresPB = new PictureBox();
                      PresPB.Location = new Point(80 + (150 * i) + 20, 50);
                      PresPB.Size = new Size(75, 75);
                      PresPB.BorderStyle = BorderStyle.Fixed3D;
                      PresPB.ImageLocation = "imgPath";
                      this.Controls.Add(PresPB);
                      PresPB.BringToFront();
                  };
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
          finally
          {
              conn.Close();
          }
      }
  </code></pre>
  
  <p>I would want the pictureboxes to be inside the groupbox and align it inside.</p>