Get a Font's Metrics in Pixels

If using a System.Windows.Forms.Control object, you can use the following code:

using (Graphics g = this.CreateGraphics())
{
    var points = myFont.SizeInPoints;
    var pixels = points * g.DpiX / 72;
    MessageBox.Show("myFont size in pixels: " + pixels);
}

Please see this article on MSDN:

How to: Obtain Font Metrics

To get pixels, you use conversion formula.

descentPixel = font.Size * descent / fontFamily.GetEmHeight(FontStyle.Regular);

Also see Get single glyph metrics (.net).

Tags:

C#

.Net

Winforms