【问题标题】:Having Trouble Recalculate Width Of RichTextBox Control无法重新计算 RichTextBox 控件的宽度
【发布时间】:2011-03-05 02:48:09
【问题描述】:

我正在创建这个程序,它需要重新计算 RichTextBox 控件的宽度。问题是它不断地重新计算错误。我使用正确的公式将点转换为英寸,然后将英寸转换为像素,然后像素乘以字符数来获得宽度。下面是代码:

        foreach (RichTextBox r in panel1.Controls)
        {


            if (r.DisplayRectangle.IntersectsWith(contextMenuStrip1.DisplayRectangle))
            {

                Graphics gfx = this.CreateGraphics();
                float dpix = gfx.DpiX;
                float dpiy = gfx.DpiY;
                int numofchars =  r.TextLength;
                float point = r.Font.SizeInPoints;
                float inches = point / 72;
                float pixels = dpiy * inches;
                float width = (pixels * numofchars);
                r.Width = Convert.ToInt32(width);


            }
        }

【问题讨论】:

    标签: c# .net visual-studio-2010 richtextbox dpi


    【解决方案1】:

    您是否尝试过查看Graphics.MeasureString 方法?

    【讨论】:

    • 谢谢,我不知道子程序存在。它让我的生活更加简单。
    猜你喜欢
    • 2017-02-03
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多