public Size GetTextExtent(string text, WindowsFont font) { if (string.IsNullOrEmpty(text)) { return(Size.Empty); } IntNativeMethods.SIZE size = new IntNativeMethods.SIZE(); HandleRef hDC = new HandleRef(null, this.dc.Hdc); if (font != null) { this.dc.SelectFont(font); } IntUnsafeNativeMethods.GetTextExtentPoint32(hDC, text, size); if ((font != null) && !MeasurementDCInfo.IsMeasurementDC(this.dc)) { this.dc.ResetFont(); } return(new Size(size.cx, size.cy)); }