Skybound VisualStyles

ThemePaint.DrawBackground Method (Graphics, Control, Rectangle, Boolean)

Draws the background of the parent of a specified control that supports visual styles, and specifies whether to ignore the background color of the control.

[Visual Basic]
Overloads Public Shared Sub DrawBackground( _
   ByVal g As Graphics, _
   ByVal ctl As Control, _
   ByVal clipBounds As Rectangle, _
   ByVal ignoreBackColor As Boolean _
)
[C#]
public static void DrawBackground(
   Graphics g,
   Control ctl,
   Rectangle clipBounds,
   bool ignoreBackColor
);

Parameters

g
The Graphics object to draw.
ctl
The Control to draw.
clipBounds
Specifies the clipping rectangle in which the background is drawn.
ignoreBackColor
True if the background should be drawn regardless of the background color of the control; otherwise, false, and the background is only drawn if the background color of the control is SystemColors.Control.

Remarks

Call this method first when drawing a control that has a transparent background. That way, if the control is placed on a tab page, rebar, or another control that has a special themed background, it will draw the background properly.

Calling this method when visual styles are not enabled or not supported by the operating system has no effect.

This example overrides the OnPaint method of a Control that has a transparent background. When visual styles are enabled, the background is drawn using the Theme API. Otherwise, the background is cleared to the background color of the control. The transparent background will draw correctly on tab pages, rebars, or other controls that have specifed themed backgrounds.

protected override void OnPaint(PaintEventArgs e)
{
  if (ThemeInformation.VisualStylesEnabled)
  {
    ThemePaint.DrawBackground(e.Graphics, this, e.ClipRectangle);
  }
  else
  {
    using (Brush brush = new SolidBrush(this.BackColor))
    {
      e.Graphics.FillRectangle(brush, e.ClipRectangle);
    }
  }
}

See Also

ThemePaint Class | Skybound.VisualStyles Namespace | ThemePaint.DrawBackground Overload List