Take a GroupBox , put the Label inside, and then set AutoSizeMode = GrowAndShrink and AutoSize = true .
There are two problems:
- There is a huge gap between the
Label and the bottom of the GroupBox (almost enough to fit another Label lol); AutoSize does not GroupBox.Text property.
The question is how to make GroupBox.AutoSize workable ? Correctly means: the minimum width should be sufficient to match GroupBox.Text , for some unknown reason there should be no spaces (this is not Margin , nor Padding , and it looks pretty ugly).
I tried to measure the string length in OnPaint and set MinimumSize right there. It works, but I doubt it, as if I would like to install MinimumSize later - it will be lost after redrawing.
Refresh, here is a screenshot:

c # winforms autosize groupbox
Sinatr
source share