public Size MeasureText(string text, Font font) { IntPtr hgdiobj = font.ToHfont(); IntPtr ptr2 = WindowsAPIUtility.SelectObject(this.graphicsHandle, hgdiobj); Size size = this.MeassureTextInternal(text); WindowsAPIUtility.SelectObject(this.graphicsHandle, ptr2); WindowsAPIUtility.DeleteObject(hgdiobj); return(size); }
public void DrawText(string text, Point point, Font font, Color foreColor) { WindowsAPIUtility.RECT rect = new WindowsAPIUtility.RECT(); IntPtr hgdiobj = font.ToHfont(); IntPtr ptr2 = WindowsAPIUtility.SelectObject(this.graphicsHandle, hgdiobj); int iBkMode = WindowsAPIUtility.SetBkMode(this.graphicsHandle, 1); int crColor = WindowsAPIUtility.SetTextColor(this.graphicsHandle, Color.FromArgb(0, foreColor.R, foreColor.G, foreColor.B).ToArgb()); Size size = this.MeassureTextInternal(text); rect = new WindowsAPIUtility.RECT { left = point.X, top = point.Y, right = rect.left + size.Width, bottom = rect.top + size.Height }; WindowsAPIUtility.DrawText(this.graphicsHandle, text, text.Length, ref rect, 0x20); WindowsAPIUtility.SetTextColor(this.graphicsHandle, crColor); WindowsAPIUtility.SetBkMode(this.graphicsHandle, iBkMode); WindowsAPIUtility.SelectObject(this.graphicsHandle, ptr2); WindowsAPIUtility.DeleteObject(hgdiobj); }