GroupBox 类

表示一个 Windows 控件,该控件显示围绕一组具有可选标题的控件的框架。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class GroupBox
    Inherits Control
用法
Dim instance As GroupBox
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class GroupBox : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class GroupBox : public Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class GroupBox extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class GroupBox extends Control

备注

GroupBox 显示围绕一组控件的框架(带或不带标题)。使用 GroupBox 对窗体上的控件集合进行逻辑分组。组框是可用于定义控件组的容器控件。

组框的典型用途是包含 RadioButton 控件的逻辑组。如果有两个分组框,每个分组框都包含多个选项按钮(也称为单选按钮),每组按钮都互相排斥,则每组设置一个选项值。

通过使用 Controls 属性的 Add 方法,可将控件添加到 GroupBox

提示

只有 GroupBox 控件中包含的控件才可以被选中或接收焦点。整个 GroupBox 本身不能被选中或者接收焦点。有关此控件如何响应 FocusSelect 方法的更多信息,请参见以下 Control 成员:CanFocusCanSelectFocusedContainsFocusFocusSelect

GroupBox 不能显示滚动条。如果需要可包含滚动条的类似于 GroupBox 的控件,请参见 Panel 控件。

示例

下面的代码示例实例化并创建一个 GroupBox 和两个 RadioButton 控件。向组框中添加单选按钮,并将该组框添加到 Form 中。

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
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 = gcnew GroupBox;
      RadioButton^ radioButton1 = gcnew RadioButton;
      RadioButton^ radioButton2 = gcnew RadioButton;
      
      // 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)
}

继承层次结构

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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

GroupBox 成员
System.Windows.Forms 命名空间
Panel
RadioButton
ControlStyles.Selectable