Open In App

C# | GroupBox Class

In Windows form, GroupBox is a container which contains multiple controls on it and the controls are related to each other. Or in other words, GroupBox is a frame display around a group of controls with a suitable optional title. Or a GroupBox is used to categorize the related controls in a group. The GroupBox class is used to represent the windows group box and also provide different types of properties, methods, and events. It is defined under System.Windows.Forms namespace. The main use of a group box is to hold a logical group of RadioButton controls.

In C# you can create a GroupBox in the windows form by using two different ways:



1. Design-Time: It is the easiest way to create a GroupBox as shown in the following steps:

2. Run-Time: It is a little bit trickier than the above method. In this method, you can create a GroupBox programmatically with the help of syntax provided by the GroupBox class. The following steps show how to set the create GroupBox dynamically:

Constructor

Constructor Description
GroupBox() This Constructors is used to initializes a new instance of the GroupBox class.

Properties

Property Description
AutoSize This property is used to get or set a value that indicates whether the control resizes based on its contents.
AutoSizeMode This property indicates how the GroupBox behaves when its AutoSize property is enabled.
BackColor This property is used to get or set the background color for the control.
BorderStyle This property indicates the border style for the control.
DisplayRectangle This property is used to get a rectangle that represents the dimensions of the GroupBox.
Font This property is used to get or set the font of the text displayed by the control.
ForeColor This property is used to get or set the foreground color of the control.
Height This property is used to get or set the height of the control.
Location This property is used to get or set the coordinates of the upper-left corner of the GroupBox control relative to the upper-left corner of its form.
Name This property is used to get or set the name of the control.
TabStop This property is used to get or set a value that shows whether the user can press the TAB key to provide the focus to the GroupBox.
Size This property is used to get or set the height and width of the control.
Visible This property is used to get or set a value indicating whether the control and all its child controls are displayed.
Width This property is used to get or set the width of the control.

Article Tags :
C#