Export (0) Print
Expand All

GroupBox Class

Represents a Windows group box.

For a list of all members of this type, see GroupBox Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.GroupBox

[Visual Basic]
Public Class GroupBox
   Inherits Control
[C#]
public class GroupBox : Control
[C++]
public __gc class GroupBox : public Control
[JScript]
public class GroupBox extends Control

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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 containing several 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 contained within the GroupBox control can be selected or receive focus. The entire 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.

Example

The following 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.

[Visual Basic] 
Private Sub InitializeMyGroupBox()
   ' Create and initialize a GroupBox and two RadioButton controls.
   Dim groupBox1 As New GroupBox()
   Dim radioButton1 As New RadioButton()
   Dim radioButton2 As 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)
End Sub 'InitializeMyGroupBox

[C#] 
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);
}
 

[C++] 
private:
    void InitializeMyGroupBox() {
        // Create and initialize a GroupBox and two RadioButton controls.
        GroupBox __gc *groupBox1 = new GroupBox();
        RadioButton __gc *radioButton1 = new RadioButton();
        RadioButton __gc *radioButton2 = new RadioButton();
     
        // Add the RadioButtons to the GroupBox.
        groupBox1->Controls->Add(radioButton1);
        groupBox1->Controls->Add(radioButton2);
 
        // Add the GroupBox to the Form.
        Controls->Add(groupBox1);
    };
 

[JScript] 
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)
}

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

GroupBox Members | System.Windows.Forms Namespace | RadioButton | ControlStyles.Selectable

Show:
© 2014 Microsoft