GroupBox Class
Represents a Windows control that displays a frame around a group of controls with an optional caption.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The GroupBox displays a frame around a group of controls with or without a caption. Use a GroupBox to logically group a collection of controls on a form. The group box is a container control that can be used to define groups of controls.
The typical use for a group box is to contain a logical group of RadioButton controls. If you have two group boxes, each of which contain several option buttons (also known as radio buttons), each group of buttons is mutually exclusive, setting one option value per group.
You can add controls to the GroupBox by using the Add method of the Controls property.
Note: |
|---|
Only controls that are contained within the GroupBox control can be selected or receive focus. The complete GroupBox itself cannot be selected or receive focus. For more information about how this control responds to the Focus and Select methods, see the following Control members: CanFocus, CanSelect, Focused, ContainsFocus, Focus, Select. |
The GroupBox cannot display a scroll bar. If you need a control similar to a GroupBox that can contain a scroll bar, see the Panel control.
The following code example instantiates and creates a GroupBox and two RadioButton controls. The radio buttons are added to the group box and the group box is added to the Form.
Private Sub InitializeMyGroupBox() ' Create and initialize a GroupBox and a Button control. Dim groupBox1 As New GroupBox() Dim button1 As New Button() button1.Location = New Point(20, 10) ' Set the FlatStyle of the GroupBox. groupBox1.FlatStyle = FlatStyle.Flat ' Add the Button to the GroupBox. groupBox1.Controls.Add(button1) ' Add the GroupBox to the Form. Controls.Add(groupBox1) ' Create and initialize a GroupBox and a Button control. Dim groupBox2 As New GroupBox() Dim button2 As New Button() button2.Location = New Point(20, 10) groupBox2.Location = New Point(0, 120) ' Set the FlatStyle of the GroupBox. groupBox2.FlatStyle = FlatStyle.Standard ' Add the Button to the GroupBox. groupBox2.Controls.Add(button2) ' Add the GroupBox to the Form. Controls.Add(groupBox2) End Sub
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.GroupBox
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: