Windows Forms GroupBox controls are used to provide other controls with an identifiable grouping. Using group boxes, you typically subdivide a form by function.
For example, We may have an order form that specifies mailing options such as which overnight carrier to use. Grouping all options in a group box gives the user a logical visual cue, and at design time all the controls can be moved easily
— when we move the single GroupBox control, all its contained controls move, too.
The caption of the group box is defined by the property Text
.
The control of the GroupBox is similar to the PanelControl but only the control of the GroupBox displays a
caption and only the PanelControl can display scroll bars.
A GroupBox's
Text
property represents a GroupBox control's header text. The following code snippet sets a GroupBox control header.
private void frmGroupBox_Load(object sender, EventArgs e)
{
groupBox1.Text = "Contact Details";
}
using System;
using System.Windows.Forms;
namespace GroupBoxControl
{
public partial class frmGroupBox : Form
{
public frmGroupBox()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnOK_Click(object sender, EventArgs e)
{
grb1.Enabled = true;
}
private void btnMessage_Click(object sender, EventArgs e)
{
MessageBox.Show("Your Enter Values: " +"Name: "+ txtName.Text +"Email ID: "+ txtEmailID.Text + "Contact No: "+txtContactNo.Text);
grb1.Enabled = false;
}
private void frmGroupBox_Load(object sender, EventArgs e)
{
grb1.Text = "Contact Details";
}
}
}