Export (0) Print
Expand All

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
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class GroupBox extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class GroupBox extends 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 two RadioButton controls.
   GroupBox groupBox1 = new GroupBox();
   RadioButton radioButton1 = new RadioButton();
   RadioButton radioButton2 = new RadioButton();

   // Set the FlatStyle of the GroupBox.
   groupBox1.FlatStyle = FlatStyle.System;
 
   // Add the RadioButtons to the GroupBox.
   groupBox1.Controls.Add(radioButton1);
   groupBox1.Controls.Add(radioButton2);
 
   // Add the GroupBox to the Form.
   Controls.Add(groupBox1);
}
 

private void InitializeMyGroupBox()
{
    // Create and initialize a GroupBox and two RadioButton controls.
    GroupBox groupBox1 = new GroupBox();
    RadioButton radioButton1 = new RadioButton();
    RadioButton radioButton2 = new RadioButton();

    // Set the FlatStyle of the GroupBox.
    groupBox1.set_FlatStyle(FlatStyle.System);

    // Add the RadioButtons to the GroupBox.
    groupBox1.get_Controls().Add(radioButton1);
    groupBox1.get_Controls().Add(radioButton2);

    // Add the GroupBox to the Form.
    get_Controls().Add(groupBox1);
} //InitializeMyGroupBox

function InitializeMyGroupBox(){
   // Create and initialize a GroupBox and two RadioButton controls.
   var groupBox1 : GroupBox = new GroupBox()
   var radioButton1 : RadioButton = new RadioButton()
   var radioButton2 : RadioButton = new RadioButton()

   // Set the FlatStyle of the GroupBox.
   groupBox1.FlatStyle = FlatStyle.System	
        
   // Add the RadioButtons to the GroupBox.
   groupBox1.Controls.Add(radioButton1)
   groupBox1.Controls.Add(radioButton2)
        
   // Add the GroupBox to the Form.
    Controls.Add(groupBox1)
}

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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft