/// <summary> /// Returns the content area for the background of the current part. /// </summary> /// <param name="hdc">The GDI device context to use.</param> /// <param name="state">The state of the part.</param> /// <param name="bounds">A <see cref="Rectangle"/> which contains the entire background area of the part.</param> /// <returns></returns> public Rectangle GetBackgroundContentRectangle(IntPtr hdc, int state, Rectangle bounds) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT rcBounds = new ThemeInternal.RECT(bounds); ThemeInternal.RECT rcContent; if (ThemeInternal.UxTheme.GetThemeBackgroundContentRect(theme.Handle, hdc, this.PartID, state, ref rcBounds, out rcContent) == 0) return rcContent.ToRectangle(); } } } return bounds; }
/// <summary> /// Inflates or deflates a rectangle based on the margins for the current part. /// </summary> /// <param name="state">The theme state constant for which the margins are defined.</param> /// <param name="bounds">The rectangle to adjust.</param> /// <param name="margin">One of the <see cref="ThemeMargin"/> constants, which determines the margins to use.</param> /// <returns></returns> public Rectangle AdjustRectangle(int state, Rectangle bounds, ThemeMargin margin) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT prc = new ThemeInternal.RECT(bounds); int [] margins = new int[4]; if (ThemeInternal.UxTheme.GetThemeMargins(theme.Handle, IntPtr.Zero, this.PartID, state, (int)margin, ref prc, margins) == 0) return Rectangle.FromLTRB( bounds.X + margins[0], bounds.Y + margins[2], bounds.Right - margins[1], bounds.Bottom - margins[3] ); } } } return bounds; }
/// <summary> /// Draws text onto a GDI device context within the specified bounding rectangle, with the option of displaying disabled text /// and applying other text formatting. /// </summary> /// <param name="hdc">The GDI device context on which the text is drawn.</param> /// <param name="state">The theme state constant for which the text is drawn.</param> /// <param name="bounds">The bounding rectangle in which the text is drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="disabled">True if the text should be drawn disabled; otherwise, false, and the text is drawn normally.</param> /// <param name="flags">A bitwise combination of the <see cref="ThemeTextFormatFlags"/> values.</param> public void DrawText(IntPtr hdc, int state, Rectangle bounds, string text, bool disabled, ThemeTextFormatFlags flags) { if (Supported && text != null && text.Length > 0 && hdc != IntPtr.Zero) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT prc = new ThemeInternal.RECT(bounds); ThemeInternal.UxTheme.DrawThemeText(theme.Handle, hdc, this.PartID, state, text, text.Length, (int)flags, disabled ? 1 : 0, ref prc); } } } }
/// <summary> /// Draws the part defined by the current renderer onto a specified device context, within the /// given clipping bounds, and using the specified <see cref="ThemeDrawFlags"/>. /// </summary> /// <param name="hdc">The GDI device context on which the part is drawn.</param> /// <param name="state">A constant which determines the current state of the part.</param> /// <param name="bounds">The bounding rectangle in which the part is drawn.</param> /// <param name="clipBounds">The bounding rectangle in which the part is clipped.</param> /// <param name="flags">A combination of <see cref="ThemeDrawFlags"/> which specify additional /// options used to draw the part.</param> public void Draw(IntPtr hdc, int state, Rectangle bounds, Rectangle clipBounds, ThemeDrawFlags flags) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { if ((flags & ThemeDrawFlags.UseDCOrigin) == ThemeDrawFlags.UseDCOrigin) { ThemeInternal.POINTAPI lpPoint; ThemeInternal.GetWindowOrgEx(hdc, out lpPoint); bounds.Offset(lpPoint.X*2, lpPoint.Y*2); clipBounds.Offset(lpPoint.X*2, lpPoint.Y*2); flags &= ~ThemeDrawFlags.UseDCOrigin; } ThemeInternal.RECT rect = new ThemeInternal.RECT(bounds); ThemeInternal.DTBGOPTS pOptions = new ThemeInternal.DTBGOPTS(); pOptions.dwSize = Marshal.SizeOf(typeof(ThemeInternal.DTBGOPTS)); pOptions.dwFlags = (int)flags; pOptions.rcClip = new ThemeInternal.RECT(clipBounds); ThemeInternal.UxTheme.DrawThemeBackgroundEx( theme.Handle, hdc, PartID, state, ref rect, ref pOptions); } } }
void DrawCore(IntPtr hdc, int state, Rectangle bounds, Rectangle clipBounds) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT rect = new ThemeInternal.RECT(bounds); ThemeInternal.RECT clipRect = new ThemeInternal.RECT(clipBounds); ThemeInternal.UxTheme.DrawThemeBackground( theme.Handle, hdc, PartID, state, ref rect, ref clipRect); } } }
/// <summary> /// Paints the background of a <see cref="Control"/> onto a GDI device context. /// </summary> /// <param name="control">The <see cref="Control"/> whose background is painted.</param> /// <param name="hdc">The GDI device context onto which the background is drawn.</param> /// <param name="clipBounds">The bounding rectangle in which the backgrounds is clipped.</param> static public void PaintBackground(Control control, IntPtr hdc, Rectangle clipBounds) { ThemeInternal.RECT rect = new ThemeInternal.RECT(clipBounds); ThemeInternal.UxTheme.DrawThemeParentBackground(control.Handle, hdc, ref rect); }