Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

GroupBox Class

Represents a Windows control that displays a frame around a group of controls with an optional caption.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class GroupBox : Control

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.

NoteNote:

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 void InitializeMyGroupBox()
{
   // Create and initialize a GroupBox and a Button control.
            GroupBox groupBox1 = new GroupBox();
            Button button1 = 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.
            GroupBox groupBox2 = new GroupBox();
            Button button2 = 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);
}
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.