/// <summary> /// Draws glowing text in the specified bounding rectangle with the option of overriding text color and applying other text formatting. /// </summary> /// <param name="rnd">The <see cref="VisualStyleRenderer" /> instance.</param> /// <param name="dc">The <see cref="IDeviceContext" /> used to draw the text.</param> /// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="font">Optional font override.</param> /// <param name="color">Optionally, the color to draw text in overriding the default color for the theme.</param> /// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <param name="glowSize">The size of the glow.</param> public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color?color, TextFormatFlags flags = TextFormatFlags.Default, int glowSize = 10) { var ht = new SafeThemeHandle(rnd.Handle, false); DrawWrapper(dc, bounds, memoryHdc => { // Create and select font using (new SafeDCObjectHandle(memoryHdc, font?.ToHfont() ?? IntPtr.Zero)) { // Draw glowing text var dttOpts = new DrawThemeTextOptions(null) { GlowSize = glowSize, AntiAliasedAlpha = true }; if (color != null) { dttOpts.TextColor = color.Value; } var textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(ht, memoryHdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref textBounds, ref dttOpts); } } ); }
public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color color, System.Windows.Forms.TextFormatFlags flags) { DrawWrapper(rnd, dc, bounds, delegate(IntPtr memoryHdc) { // Create and select font using (SafeDCObjectHandle fontHandle = new SafeDCObjectHandle(memoryHdc, font.ToHfont())) { // Draw glowing text DrawThemeTextOptions dttOpts = new DrawThemeTextOptions(true); dttOpts.TextColor = color; dttOpts.GlowSize = 10; dttOpts.AntiAliasedAlpha = true; RECT textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(rnd.Handle, memoryHdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref textBounds, ref dttOpts); } } ); }
public static extern int DrawThemeTextEx(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int iCharCount, TextFormatFlags dwFlags, ref RECT pRect, ref DrawThemeTextOptions pOptions);
/// <summary> /// Draws text in the specified bounding rectangle with the option of applying other text formatting. /// </summary> /// <param name="rnd">The <see cref="VisualStyleRenderer" /> instance.</param> /// <param name="dc">The <see cref="IDeviceContext" /> used to draw the text.</param> /// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags"/> values.</param> /// <param name="options">The <see cref="DrawThemeTextOptions"/> .</param> public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, TextFormatFlags flags, ref DrawThemeTextOptions options) { var rc = new RECT(bounds); using (var hdc = new SafeDCHandle(dc)) DrawThemeTextEx(rnd, hdc, rnd.Part, rnd.State, text, text.Length, flags, ref rc, ref options); bounds = rc; }
public static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref NativeMethods.RECT pRect, ref DrawThemeTextOptions pOptions);
public static extern void DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref NativeMethods.RECT pRect, ref DrawThemeTextOptions pOptions);
/*public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color color, System.Windows.Forms.TextFormatFlags flags) { using (SafeGDIHandle primaryHdc = new SafeGDIHandle(dc)) { // Create a memory DC so we can work offscreen using (SafeCompatibleDCHandle memoryHdc = new SafeCompatibleDCHandle(primaryHdc)) { // Create a device-independent bitmap and select it into our DC BITMAPINFO info = new BITMAPINFO(bounds.Width, -bounds.Height); using (SafeDCObjectHandle dib = new SafeDCObjectHandle(memoryHdc, GDI.CreateDIBSection(primaryHdc, ref info, 0, 0, IntPtr.Zero, 0))) { // Create and select font using (SafeDCObjectHandle fontHandle = new SafeDCObjectHandle(memoryHdc, font.ToHfont())) { // Draw glowing text DrawThemeTextOptions dttOpts = new DrawThemeTextOptions(true); dttOpts.TextColor = color; dttOpts.GlowSize = 10; dttOpts.AntiAliasedAlpha = true; RECT textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); DrawThemeTextEx(rnd.Handle, memoryHdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; GDI.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); } } } } }*/ public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, System.Windows.Forms.TextFormatFlags flags, DrawThemeTextOptions options) { RECT rc = new RECT(bounds); using (SafeGDIHandle hdc = new SafeGDIHandle(dc)) DrawThemeTextEx(rnd.Handle, hdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref rc, ref options); bounds = rc.ToRectangle(); }
static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DrawThemeTextOptions pOptions);
/*public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color color, System.Windows.Forms.TextFormatFlags flags) * { * using (SafeGDIHandle primaryHdc = new SafeGDIHandle(dc)) * { * // Create a memory DC so we can work offscreen * using (SafeCompatibleDCHandle memoryHdc = new SafeCompatibleDCHandle(primaryHdc)) * { * // Create a device-independent bitmap and select it into our DC * BITMAPINFO info = new BITMAPINFO(bounds.Width, -bounds.Height); * using (SafeDCObjectHandle dib = new SafeDCObjectHandle(memoryHdc, GDI.CreateDIBSection(primaryHdc, ref info, 0, 0, IntPtr.Zero, 0))) * { * // Create and select font * using (SafeDCObjectHandle fontHandle = new SafeDCObjectHandle(memoryHdc, font.ToHfont())) * { * // Draw glowing text * DrawThemeTextOptions dttOpts = new DrawThemeTextOptions(true); * dttOpts.TextColor = color; * dttOpts.GlowSize = 10; * dttOpts.AntiAliasedAlpha = true; * RECT textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); * DrawThemeTextEx(rnd.Handle, memoryHdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref textBounds, ref dttOpts); * * // Copy to foreground * const int SRCCOPY = 0x00CC0020; * GDI.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); * } * } * } * } * }*/ public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, System.Windows.Forms.TextFormatFlags flags, DrawThemeTextOptions options) { RECT rc = new RECT(bounds); using (SafeGDIHandle hdc = new SafeGDIHandle(dc)) DrawThemeTextEx(rnd.Handle, hdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref rc, ref options); bounds = rc.ToRectangle(); }