Intermediate
8 min read
Control #7
GroupBox Control
The GroupBox is a container control that groups related controls together with a visible border and title.
What is a GroupBox?
A GroupBox is a container that visually groups related controls. It has a border with a title that helps users understand that the controls inside belong together. Perfect for RadioButton grouping.
Code Example
// Create a GroupBox
GroupBox gbPayment = new GroupBox();
gbPayment.Text = "Payment Method";
gbPayment.Location = new Point(20, 20);
gbPayment.Size = new Size(200, 150);
// Add RadioButtons to the GroupBox
RadioButton rbCredit = new RadioButton();
rbCredit.Text = "Credit Card";
rbCredit.Location = new Point(10, 20);
gbPayment.Controls.Add(rbCredit);
// RadioButtons in the same GroupBox are automatically grouped
Exercise
Task: Create a survey form with GroupBox controls.
- Add a GroupBox: "Personal Information".
- Add a GroupBox: "Favorite Programming Language".
- Add a GroupBox: "Experience Level".
- Add RadioButtons inside each GroupBox.
- Add a Button to show all selections.
Key Takeaway
Use GroupBox to organize related controls. It automatically groups RadioButtons so only one can be selected per GroupBox.