本文介绍了分组框中自动调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以一个分组框,把让说标签里面,然后设置 AutoSizeMode = GrowAndShrink 自动调整大小=真

Take a GroupBox, put let say Label inside and then set AutoSizeMode = GrowAndShrink and AutoSize = true.

两个问题会出现:


  • 分组框和底部之间的巨大差距C $ C>(几乎足以容纳另一个标签笑);

  • 自动调整大小不尊重 GroupBox.Text 属性。

  • There is a huge gap between Label and bottom of GroupBox (almost enough to fit another Label lol);
  • AutoSize doesn't respect the GroupBox.Text property.

问题如何让 GroupBox.AutoSize 正常工作?正确的意思是:最小宽度应足以满足 GroupBox.Text ,应该有以下不明原因无间隙(这不是保证金,也不填充和它看起来很丑陋)。

Question is how to make GroupBox.AutoSize working properly? Properly means: minimum Width should be enough to fit GroupBox.Text, there should be no gaps below for unknown reason (it's not Margin, nor Padding and it looks pretty ugly).

我试图来衡量的OnPaint 并设置的minimumSize 在那里。它的工作原理,但我怀疑这一点,因为如果我想实际设置的minimumSize 之后 - 这将重绘后丢失

I've tried to measure string length in OnPaint and setting MinimumSize right there. It works, but I have doubts about this, as if I would want to actually set MinimumSize later - it will be lost after repaint.

更新,下面是截图:

推荐答案

这很简单那的位置你标签被固定在比其他一些点(0,0),试试这个:

It's simple that the location of your Label is fixed at some point other than (0,0), try this:

label1.Location = Point.Empty;

您也可以尝试设置填充你的分组框 0 所有(默认为3):

You may also want to try setting the Padding of your GroupBox to 0 for all (default is 3):

groupBox1.Padding = new Padding(0);

这篇关于分组框中自动调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 18:04