String's display width?

  • Thread starter Thread starter mmobile
  • Start date Start date
M

mmobile

How can I get the size (in pixels) of a string's display width (based on the
Font used)?
 
By using Graphics' object MeasureString method. e.g.

Dim textWidth as integer =
Convert.ToInt32(Me.CreateGraphics.MeasureString(lblName.Text,
lblName.Font).Width)
 
Use MeasureString for that:

using(Graphics g = (new Control()).CreateGraphics())
{
SizeF sz = g.MeasureString("Hello World", SpecificFont);
}
 
Back
Top