【问题标题】:Resize the textBox and pictureBox in C# windowform在 C# windows 窗体中调整文本框和图片框的大小
【发布时间】:2019-07-17 21:38:25
【问题描述】:

标签中的文本位于调整文本大小的代码下方,但文本框和图片框的位置移动不同,这意味着当我拉动整个页面时,文本框一个向上移动,另外两个向下移动.. ..见下图链接。

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

【问题讨论】:

    标签: c# tablelayout


    【解决方案1】:

    与“地址”文本框设置代码相比,在为表单生成的 .cs 文件中检查“名称”文本框和“合同编号”文本框的对齐和停靠属性以及字体属性

    【讨论】:

      猜你喜欢
      • 2014-07-21
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 2019-01-05
      相关资源
      最近更新 更多