private static Size GetCharSize(Font font)
{
const string measure_string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
IntPtr hdc = NativeMethods.CreateCompatibleDC(IntPtr.Zero);
NativeMethods.SelectObject(hdc, font.ToHfont());
NativeMethods.TEXTMETRIC tm;
NativeMethods.GetTextMetrics(hdc, out tm);
NativeMethods.SIZE size;
NativeMethods.GetTextExtentPoint32(hdc, measure_string, measure_string.Length, out size);
NativeMethods.DeleteDC(hdc);
return new Size((int)Math.Round((double)size.cx / (double)measure_string.Length), tm.tmHeight);
}
}