Open In App

How to set the Auto Size Mode of the GroupBox in C#?

In Windows Forms, GroupBox is a container which contains multiple controls in 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. In GroupBox, you can set a value which indicates how GroupBox behaves when the value of the AutoSize Property is set to true, using AutoSizeMode Property. The value of this property is defined under AutoSizeMode enum and the values are:

The default value of this property is GrowOnly. You can set this property in two different ways:



1. Design-Time: It is the easiest way to set the AutoSizeMode property of the 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 set how GroupBox behave when the AutoSize property set to be true, programmatically with the help of given syntax:

public System.Windows.Forms.AutoSizeMode AutoSizeMode { get; set; }

Here, AutoSizeMode is used to set the value of this property. The following steps show how to set the AutoSizeMode property of the GroupBox dynamically:


Article Tags :
C#