private static void DrawOnHDC(IntPtr compatHdc, string text, Font font, Padding internalBounds, Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) { //Create the Font to use IntPtr hFont = font.ToHfont(); Native.GDI.SelectObject(compatHdc, hFont); //Get theme renderer VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active); //Prepare options NativeMethods.DTTOPTS dttOpts = new NativeMethods.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(dttOpts); dttOpts.dwFlags = NativeMethods.DTTOPSFlags.DTT_COMPOSITED | NativeMethods.DTTOPSFlags.DTT_TEXTCOLOR; dttOpts.crText = ColorTranslator.ToWin32(color); foreach (IThemeTextOption op in options) { op.Apply(ref dttOpts); } //Set full bounds with padding Native.RECT RECT = new Native.RECT(internalBounds.Left, internalBounds.Top, bounds.Width - internalBounds.Right, bounds.Height - internalBounds.Bottom); //Draw int ret = NativeMethods.DrawThemeTextEx(renderer.Handle, compatHdc, 0, 0, text, -1, (int)formatFlags, ref RECT, ref dttOpts); if (ret != 0) { Marshal.ThrowExceptionForHR(ret); } //Clean up Native.GDI.DeleteObject(hFont); }
private static void DrawOnHDC(IntPtr compatHdc, string text, Font font, Padding internalBounds, Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) { //Create the Font to use IntPtr hFont = font.ToHfont(); Native.GDI.SelectObject(compatHdc, hFont); //Get theme renderer VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active); //Prepare options NativeMethods.DTTOPTS dttOpts = new NativeMethods.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(dttOpts); dttOpts.dwFlags = NativeMethods.DTTOPSFlags.DTT_COMPOSITED | NativeMethods.DTTOPSFlags.DTT_TEXTCOLOR; dttOpts.crText = ColorTranslator.ToWin32(color); foreach (IThemeTextOption op in options) op.Apply(ref dttOpts); //Set full bounds with padding Native.RECT RECT = new Native.RECT(internalBounds.Left, internalBounds.Top, bounds.Width - internalBounds.Right, bounds.Height - internalBounds.Bottom); //Draw int ret = NativeMethods.DrawThemeTextEx(renderer.Handle, compatHdc, 0, 0, text, -1, (int)formatFlags, ref RECT, ref dttOpts); if (ret != 0) Marshal.ThrowExceptionForHR(ret); //Clean up Native.GDI.DeleteObject(hFont); }