Group Wrap GroupBox.AutoSize and GroupBox.Text

I have two problems with GroupBox , they appear after setting GroupBox.AutoSizeMode = AutoSizeMode.GrowAndShrink and GroupBox.AutoSize = true .

Groubox bug

  • GroupBox.Text width is not taken into account at all. Selecting a size will only match the content, and then the text will be wrapped if it does not fit. If it does not fit, it simply does not appear.

  • There is an unnecessarily large gap between the bottom of the GroupBox and the Label inside.

Questions:

How to make GroupBox comply with its Text property when autosaving? And how to remove this gap?


For some reason, my previous question is paused. Should I remove it or what?

PS: If you paused or something else, comment on what is definitely not clear in what I ask!

+1
c # winforms autosize groupbox
source share
1 answer
 /* Calculate the Text Width in pixels, then set the size for the GroupBox. */ groupBoxA.SuspendLayout(); SizeF stringSizeLabel; using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1))) { Font stringFont = new Font("Microsoft Sans Serif", 8.25F); stringSizeLabel = graphics.MeasureString("SAMPLE TEXT", stringFont); } int iWidth = (int)(stringSizeLabel.Width * 1.35f); // Give a little extra width int iHeight = 78; // This is a sample value groupBoxA.Size = new System.Drawing.Size(iWidth, iHeight); groupBoxA.MinimumSize = new System.Drawing.Size(iWidth, iHeight); groupBoxA.ResumeLayout(false); groupBoxA.PerformLayout(); 
0
source share

All Articles