String's display width?

M

mmobile

How can I get the size (in pixels) of a string's display width (based on the
Font used)?
 
D

Dinesh Bajaj

By using Graphics' object MeasureString method. e.g.

Dim textWidth as integer =
Convert.ToInt32(Me.CreateGraphics.MeasureString(lblName.Text,
lblName.Font).Width)
 
S

Sergey Bogdanov

Use MeasureString for that:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top