Search code examples
c#winformsheightautosizegroupbox

AutoSize and Size property in Winforms


There is GroupBox on the Form with below properties:

AutoSize = true;
AutoSizeMode = GrowAndShrink;

It seems, if you add Control into this GroupBox, the GroupBox's height will be:

Control.Top + Control.Height + 20;

Is there any way to decrease this number ---> 20?


Solution

  • AutoSize = true means that the control will start calling the GetPreferredSize(Size proposedSize) method.

    You can subclass GroupBox and override the GetPreferredSize method.