/// <summary>Draws the image from the specified <paramref name="imageList"/> within the specified bounds on a glass background.</summary> /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param> /// <param name="g">The <see cref="Graphics"/> used to draw the image.</param> /// <param name="bounds">A <see cref="System.Drawing.Rectangle"/> in which the image is drawn.</param> /// <param name="imageList">An <see cref="ImageList"/> that contains the <see cref="Image"/> to draw.</param> /// <param name="imageIndex">The index of the <see cref="Image"/> within <paramref name="imageList"/> to draw.</param> public static void DrawGlassImage(this VisualStyleRenderer rnd, IDeviceContext g, Rectangle bounds, ImageList imageList, int imageIndex) { var ht = new SafeHTHEME(rnd.Handle, false); g.DrawViaDIB(bounds, (memoryHdc, b) => DrawThemeIcon(ht, memoryHdc, rnd.Part, rnd.State, bounds, imageList.Handle, imageIndex)); }
/// <summary> /// Draws the background image of the current visual style element onto a glass background within the specified bounding rectangle /// and optionally clipped to the specified clipping rectangle. /// </summary> /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param> /// <param name="dc">The <see cref="IDeviceContext"/> used to draw the background image.</param> /// <param name="bounds">A <see cref="System.Drawing.Rectangle"/> in which the background image is drawn.</param> /// <param name="clipRectangle">A <see cref="System.Drawing.Rectangle"/> that defines a clipping rectangle for the drawing operation.</param> /// <param name="rightToLeft">If set to <c>true</c> flip the image for right to left layout.</param> public static void DrawGlassBackground(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, Rectangle?clipRectangle = null, bool rightToLeft = false) { var ht = new SafeHTHEME(rnd.Handle, false); dc.DrawViaDIB(bounds, (memoryHdc, b) => { var rBounds = new RECT(bounds); //var opts = new DrawThemeBackgroundOptions(clipRectangle); // Draw background var oldLayout = DCLayout.GDI_ERROR; if (rightToLeft) { if ((oldLayout = SetLayout(memoryHdc, DCLayout.LAYOUT_RTL)) == DCLayout.GDI_ERROR) { throw new NotSupportedException("Unable to change graphics layout to RTL."); } } DrawThemeBackground(ht, memoryHdc, rnd.Part, rnd.State, rBounds, clipRectangle); if (oldLayout != DCLayout.GDI_ERROR) { SetLayout(memoryHdc, oldLayout); } } ); }
/// <summary>Draws the specified image within the specified bounds on a glass background.</summary> /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param> /// <param name="g">The <see cref="Graphics"/> used to draw the image.</param> /// <param name="bounds">A <see cref="System.Drawing.Rectangle"/> in which the image is drawn.</param> /// <param name="image">An <see cref="ImageList"/> that contains the <see cref="Image"/> to draw.</param> /// <param name="disabled"> /// if set to <c>true</c> draws the image in a disabled state using the <see cref="ControlPaint.DrawImageDisabled"/> method. /// </param> public static void DrawGlassImage(this VisualStyleRenderer rnd, IDeviceContext g, Rectangle bounds, Image image, bool disabled = false) { g.DrawViaDIB(bounds, (memoryHdc, b) => { using (var mg = Graphics.FromHdc(memoryHdc.DangerousGetHandle())) { if (disabled) { ControlPaint.DrawImageDisabled(mg, image, bounds.X, bounds.Y, Color.Transparent); } else { mg.DrawImage(image, bounds); } } } ); }
/// <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="System.Drawing.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 SafeHTHEME(rnd.Handle, false); dc.DrawViaDIB(bounds, (memoryHdc, b) => { // Create and select font using (new GdiObjectContext(memoryHdc, new SafeHFONT(font?.ToHfont() ?? IntPtr.Zero))) { // Draw glowing text var dttOpts = new DTTOPTS(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, dttOpts); } } ); }