1
votes

I am drawing a group box at run time with dock top, and inside it I am drawing buttons of fix height and width Autosize property of group box is true. The buttons I am drawing are of less height than the default height of the group box which is acquiring at run time. How can I remove that extra lower bottom space for the group box?

GroupBox gbFreeCust = new GroupBox() 
    { 
        Dock= DockStyle.Top, 
        Text = item.CatName, 
        AutoSize = true, 
        AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly 
    };
pnlFreeCust.Controls.Add(gbFreeCust);
1
Can't you just set the groupbox's height on the buttons ones ? Something like groupbox.height = max(button1.height,button2.height)+ margin ?OlivierH

1 Answers

1
votes

Try to set the Padding or the MinimumSize properties:

GroupBox gbFreeCust = new GroupBox() 
    { 
        Dock= DockStyle.Top, 
        Text = item.CatName, 
        AutoSize = true, 
        AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly,
        Padding = new System.Windows.Forms.Padding(0),
        MinimumSize = new Size(0,0)
    };
pnlFreeCust.Controls.Add(gbFreeCust);