When drawing a string I get the required size by calling myGraphics.MeasureString(myString, myFont);
.
Experimentally I found out that this method always returns the same height for any string or single character of a certain font. So this value seems to be a feature of the font and not a feature of the string. But there is no property or method in the font class which delivers this information.
The font class has several properties / methods returning height information but none of them gives the same value as the string measurement.
Example:
using (Graphics myGraphicsTemp = CreateGraphics())
{
Font myFont = new Font("Microsoft Sans Serif", 9F);
var size = myFont.Size; // 9
var height = myFont.Height; // 14
var lineSpacing = myFont.GetHeight(); // 13.5820293
var measuredHeight = myGraphicsTemp.MeasureString("1", myFont).Height; // 15.0820284
}
I need the height given by the string measuring method at several places in my code. So I set a variable (like measuredHeight
in my example) by measuring an arbitrarily chosen character. That works but I think this has a "strong smell".
Is there a better way to find the required value?
I found the following question
(Width and height of font) but it did not answer my question.