What I am doing is getting the pixel size of the string and converting it to hundredths of an inch (i.e. pixels / DPI = inches, inches * 100 = hundredths of an inch). Here is my code:
private static SizeF TextSize(string text, Font txtFnt)
{
SizeF txtSize = new SizeF();
Size s = System.Windows.Forms.TextRenderer.MeasureText(text, txtFnt);
txtSize.Width = (float)Math.Ceiling((float)s.Width / 96f * 100f);
txtSize.Height = (float)Math.Ceiling((float)s.Height / 96f * 100f);
return txtSize;
}
Now, using the Arial font, all this works fine for fonts smaller than 12, but after that the characters begin to be cropped because the calculated size is smaller than the actual size. I know that my DPI settings are set to 96. My fonts are all the same with changing the font size:
Font myFont = new Font("Arial", <font size>, FontStyle.Regular, GraphicsUnit.Point);
I believe that I need to use GraphicsUnit.Pointbecause of the user control into which I draw the lines, but does it matter GraphicsUnit?
Is the function MeasureTexteven correct, or is something else going on?
. "Inches/100" (, ). , , .. "", .