1

When I create a GroupBox, set it's Autosize=true and AutoSizeMode=GrowAndShrink, and put some control in there (e.g. a Button) there's a large empty space below it, making the GroupBox too high:

Unwanted vertical gap

How do I get rid of this unwanted gap without manually setting the GroupBox's height?

(This question has actually been asked before here but no working answer was provided)

Community
  • 1
  • 1
jbb
  • 346
  • 3
  • 9
  • 2
    Did you check the margin and padding on each of the controls? – Dan Wilson Nov 22 '16 at 14:28
  • Bottom-margin of the button? Padding of the group-box? – Daniel Dušek Nov 22 '16 at 14:31
  • 1
    Just do this in the designer and note the dragging handles, the button is actually in the middle. It just looks out of whack because GB draws the top line too low, necessary to get it to align with the title. You can make it a little better by changing its Padding.Bottom from 3 to 0 but you can't make it negative. – Hans Passant Nov 22 '16 at 14:34
  • Actually it works just as designed. The extra space is there to allow you better dropping. It doesn't display at runtime, at least it doesn't here. – TaW Nov 22 '16 at 14:36
  • Both the `GroupBox`'s padding and the `Buttons`'s margin are set to their default values of 3 (top, bottom, left, right). They do contribute 3 pixels to the gap but that's not nearly the size of it so setting them to 0 does not solve the problem :/ – jbb Nov 22 '16 at 14:40
  • I don't think there's an easy way to get rid of that. As @HansPassant said, the button is exactly in the centre of the Groupbox,although it does not look like that because of the title. – Pikoh Nov 22 '16 at 14:41
  • In fact, if you change the font size of the groupbox to, say,1,25, you'll see that below gap disappears, but then you have it up – Pikoh Nov 22 '16 at 14:43
  • I find it strange that Microsoft would design this control with this large hardcoded gap. Wouldn't they just rather use a high default bottom margin value to get developers to follow their design standard? They already do that with their default margin value of 3 for a lot of controls. Also, they themselves don't have this gap on a lot of their group boxes.. (take a look at "Folder Options" in Control Panel for a good example with multiple group boxes with nice, equally big top and bottom margins) – jbb Nov 22 '16 at 14:57
  • The gap is the same up and down ,but you don't see it because of the groupbox text. I see it as a Autosize design fault, but that's how it is. And how do you know in "Folder Options" they are using a groupbox with autosize=true? – Pikoh Nov 22 '16 at 15:05
  • 2
    Actually, if I set `AutoSize=true` and `Dock=fill` on the button the gap goes away! The button's right and left margins however disappear and I'm not sure this is a solution that works well for other controls.. – jbb Nov 22 '16 at 15:22

0 Answers0