Step 3: And last add this GroupBox control to the form and also add other controls on the GroupBox using the following statements:
```cs
// Adding groupbox in the form
this.Controls.Add(gbox);
and
// Adding this control
// to the GroupBox
gbox.Controls.Add(c2);
```
示例:
```cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp46 {
public partial class Form1 : Form {
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Creating and setting
// properties of the GroupBox
GroupBox gbox = new GroupBox();
gbox.Location = new Point(179, 145);
gbox.Text = "Select Gender";
gbox.Name = "Mybox";
gbox.FOnt= new Font("Colonna MT", 12);
gbox.Visible = true;
gbox.AutoSize = true;
gbox.AutoSizeMode = AutoSizeMode.GrowAndShrink;
// Adding groupbox in the form
this.Controls.Add(gbox);
// Creating and setting
// properties of the CheckBox
CheckBox c1 = new CheckBox();
c1.Location = new Point(40, 42);
c1.Size = new Size(69, 20);
c1.Text = "Male";
// Adding this control
// to the GroupBox
gbox.Controls.Add(c1);
// Creating and setting
// properties of the CheckBox
CheckBox c2 = new CheckBox();
c2.Location = new Point(183, 39);
c2.Size = new Size(79, 20);
c2.Text = "Female";
// Adding this control
// to the GroupBox
gbox.Controls.Add(c2);
}
}
}
```
输出: