Points, Pixels and string lengths

  • Thread starter Thread starter Anne
  • Start date Start date
A

Anne

I am creating text box controls "on the fly" for strings
of varying lengths. I want to make the text box size
match the size of the string. How do I convert the length
of the string (len) to pixels, which is required by Size.
The Font is sized in Point.

aTextBox.Size = new System.Drawing.Size((len * ??? ), 20);
 
You can get the size of a string drawn with a given font with
Graphics.MeasureString();
 
Back
Top