Windows Forms:
For System.Drawing
there is a way to get the font height.
Font font = new Font("Arial", 10 , FontStyle.Regular);
float fontHeight = font.GetHeight();
But how do you get the other text metrics like average character width?
Typographers measure the cap height of a font in units called points. A point is 1/72nd of an inch. There are twelve points in a pica, and six picas equal one inch. The width of each character is called the set width.
What you're looking for is transform:scale(x, y) . For example: -webkit-transform:scale(2.0, 1.0); -moz-transform:scale(2.0, 1.0); -ms-transform:scale(2.0, 1.0); -o-transform:scale(2.0, 1.0); transform:scale(2.0,1.0);
Use Graphics.MeasureString Method
private void MeasureStringMin(PaintEventArgs e)
{
// Set up string.
string measureString = "Measure String";
Font stringFont = new Font("Arial", 16);
// Measure string.
SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(measureString, stringFont);
// Draw rectangle representing size of string.
e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 0.0F, 0.0F, stringSize.Width, stringSize.Height);
// Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, new PointF(0, 0));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With