GroupBox
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Exam 70-526 Preparation Guide: Group and arrange controls by using the GroupBox control.
|
Contents |
The GroupBox control displays a frame around a group of controls with or without a caption. GroupBoxes are used to subdivide a form by function, giving the user a logical visual cue of control grouping
You can add controls to the GroupBox at design time and runtime. When you move the GroupBox control, all of its contained controls move too.
When you create a new group box, it has a border by default, and its caption is set to the name of the control
[edit]
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.GroupBox
[edit]
Useful properties
-
BackColor- The background colour of the panel is defaulted toSystem.Drawing.SystemColors.Control, but this can be set to any colour you like
-
-
BackgroundImage- Instead of a single colour, an image can be displayed as the background.
-
-
Controls- Gets the collection of controls contained within the control.
-
-
Enabled- if this property is set tofalse, the controls contained within theGroupBoxwill also be disabled.
-
-
FlatStyle- Gets or sets the flat style appearance of the group box control.
-
-
TabIndex- Gets or sets the tab order of the control within its container. (inherited fromControl).
-
-
TabStop- Gets or sets a value indicating whether the user can give the focus to this control using the TAB key.
-
-
Text- Caption text.
-
Note:
|
[edit]
Add a control to a GroupBox manually
The GroupBox control MSDN page has the following example showing how to add a GroupBox and some controls within it.
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); }
[edit]
MSDN references
|
© 2007-2008 Mike Kitchen


