Wednesday, July 21, 2010

C# Determine the pixel length of a string.

This method will determine the length in pixels of the text.

private float FindLengthString(string text)
        { 
            Font _tagFont = new Font("Sans Serif", 8.25f);
            float fWidth = _tagFont.Size;

            Graphics g = this.CreateGraphics();
            fWidth = g.MeasureString(text, _tagFont).Width;
            g.Dispose();

            return fWidth;
        }

No comments:

Post a Comment