How can I compute the width of a string in pixels?

  • Thread starter Thread starter smartnose
  • Start date Start date
S

smartnose

say, when I have set the font and get a string like "hello world", how can I
compute the exact space this string will take when I paint it on a form?
Thank you.
 
What you are looking for is the method MeasureString()

public SizeF MeasureString(string, Font);

which is called from a Graphics object.
 
Back
Top