开发者

Having Trouble Recalculate Width Of RichTextBox Control

I am creating this program that requires the recalculation of a RichTextBox control's width. The problem is that it keeps recalculating wrong. I used the correct formulas to convert point to inches, then inches to pixels and then pixels times number of characters to get the width. Here is the code below:

        foreach (RichTextBox r in panel1.Controls)
        {


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

                Graphics gfx = this.Cre开发者_JS百科ateGraphics();
                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);


            }
        }


Have you tried looking into the Graphics.MeasureString Method?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜