groupBox1.SuspendLayout(); // add controls to groupBox1 textBox1.Location = new Point(10, 10); groupBox1.Controls.Add(textBox1); button1.Location = new Point(10, 40); groupBox1.Controls.Add(button1); groupBox1.ResumeLayout();
private void Form1_Load(object sender, EventArgs e) { groupBox1.SuspendLayout(); // add controls to groupBox1 for (int i = 1; i <= 5; i++) { Label label = new Label(); label.Text = "Label " + i.ToString(); label.Location = new Point(10, i * 30); groupBox1.Controls.Add(label); } groupBox1.ResumeLayout(); }In this example, we add several labels to a group box in the Form1_Load event handler. We again use SuspendLayout and ResumeLayout to prevent any unnecessary redraws while adding the controls to the group box. The System.Windows.Forms namespace is part of the .NET Framework Class Library.