/// <summary> /// Get font text metrics points. /// </summary> /// <param name="g"></param> /// <param name="hFont"></param> /// <param name="fontName"></param> /// <param name="fontSize"></param> /// <param name="retPoint"></param> public static void GetTextMetrics(Graphics g, IntPtr hFont, string fontName, int fontSize, out PointF retPoint) { retPoint = new PointF(); int dpiX = (int)g.DpiX; // create the handle of DC IntPtr hdc = g.GetHdc(); IntPtr hFontOld = (IntPtr)NativeWindowCommon.SelectObject(hdc, hFont); NativeWindowCommon.TEXTMETRIC tm; NativeWindowCommon.GetTextMetrics(hdc, out tm); retPoint.X = tm.tmAveCharWidth; retPoint.Y = tm.tmHeight; if (SpecialTextSizeFactoring && dpiX == 120) //defect 117706 { //please, create an infrastructure for this if you need to add another font ... if (fontName == "Microsoft Sans Serif" && fontSize == 8 && retPoint.X == 6) { //For 100% resolution we got tm.tmAveCharWidth = 5 (average char width) //For 125% resolution we got tm.tmAveCharWidth = 6 and in prepareUOMConversion we use this data as factor for calculating all magic sizes for all controls and form. //So, the difference between 125% resolution and 100% resolution is 6/5 = 1.2, i.e 120% which is not enough //Here we manually set factor retPoint.X = 5 * 1.275F; } } NativeWindowCommon.SelectObject(hdc, hFontOld); // release the resources g.ReleaseHdc(hdc); }