I want to measure the length of a string into pixel units. I searched the web for 2 days but got no luck. Finally, I found some code snippet a few minutes ago from a blog and modified it a little bit. Here's my function:
private void cmdMeasure_Click(object sender, EventArgs e)
{
Font fntStyle = new Font("Arial", 16, FontStyle.Regular, GraphicsUnit.Pixel);
Size textSize = TextRenderer.MeasureText(str2measure.Text, fntStyle);
MessageBox.Show(textSize.ToString());
}
Question:
What is the unit of 16? Is it em, pt, or the unit of GraphicsUnit enum? I don't really get the description defined by c# "the em-size of the new font in the units specified by the unit parameter."
Does the TextRenderer.MeasureText method include the spaces between the characters in its measurement?