[英]GroupBox.AutoSize and GroupBox.Text wrapping
我在GroupBox
遇到两个问题,它们在设置GroupBox.AutoSizeMode = AutoSizeMode.GrowAndShrink
和GroupBox.AutoSize = true
。
完全不考虑GroupBox.Text
宽度。 调整大小将仅适合内容,如果不适合,则文本将被换行。 如果无法容纳-则不会显示。
GroupBox
底部和内部的Label
之间不必要地有很大的空隙。
自动调整大小时如何使GroupBox
尊重其Text
属性? 以及如何消除这种差距?
由于某些原因,我先前的问题被搁置了。 我应该删除它还是什么?
附言:如果您暂停或进行其他操作,请评论我所要求的不清楚的地方!
/*
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.