标签中的文本在代码下方以调整文本大小,但是文本框和PictureBox的位置在移动,这意味着当我拉动整个页面时,文本框是一个向上移动,另外两个正在向下移动。 ..请参阅下面的图片链接。
public Font FlexFont(Graphics g, float minFontSize, float maxFontSize, Size layoutSize, string s, Font f, out SizeF extent)
{
if (maxFontSize == minFontSize)
f = new Font(f.FontFamily, minFontSize, f.Style);
extent = g.MeasureString(s, f);
if (maxFontSize <= minFontSize)
return f;
float hRatio = layoutSize.Height / extent.Height;
float wRatio = layoutSize.Width / extent.Width;
float ratio = (hRatio < wRatio) ? hRatio : wRatio;
float newSize = f.Size * ratio;
if (newSize < minFontSize)
newSize = minFontSize;
else if (newSize > maxFontSize)
newSize = maxFontSize;
f = new Font(f.FontFamily, newSize, f.Style);
extent = g.MeasureString(s, f);
return f;
}
internal static void OnPaint(object sender, EventArgs e, string text)
{
throw new NotImplementedException();
}
public void OnPaint(object sender, PaintEventArgs e, string text)
{
var control = sender as Control;
if (control == null)
return;
control.Text = string.Empty; //delete old stuff
var rectangle = control.ClientRectangle;
using (Font f = new Font("Microsoft Sans Serif", 20.25f, FontStyle.Bold))
{
SizeF size;
using (Font f2 = FlexFont(e.Graphics, 5, 50, rectangle.Size, text, f, out size))
{
PointF p = new PointF((rectangle.Width - size.Width) / 3, (rectangle.Height - size.Height) / 3);
e.Graphics.DrawString(text, f2, Brushes.Black, p);
}
}
页面截图:
没有拉大页面的原始页面
-https://ibb.co/P6s8hbZ
拉大页面后
-https://ibb.co/jvn7nfk
答案 0 :(得分:0)
与“地址”文本框设置代码相比,在生成的.cs文件中检查“名称”文本框和“合同编号”文本框以及字体属性的匹配和对接属性