public static Size MeasureText(string text, Font font) { using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero)) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; Size size = TextRenderer.MeasureText((IDeviceContext)graphics, text, font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding); if (TextBoxWrapPanel.IsTab(text)) { size.Width = RadGdiGraphics.GetTextMetric(font).aveCharWidth * 4; } return(size); } }
private static float GetBaseLineFromFont(Font font) { int hashCode = font.GetHashCode(); if (FormattedText.baseLines == null) { FormattedText.baseLines = new Dictionary <int, float>(4); } if (FormattedText.baseLines.ContainsKey(hashCode)) { return(FormattedText.baseLines[hashCode]); } FontTextMetrics textMetric = RadGdiGraphics.GetTextMetric(font); FormattedText.baseLines.Add(hashCode, (float)textMetric.ascent); return((float)textMetric.ascent); }