Skybound VisualStyles

ThemePaint.DrawBackground Method (Graphics, Control, Rectangle)

Draws the background of the parent of a specified control that supports visual styles.

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

Parameters

g
The Graphics object to draw.
ctl
The Control to draw.
clipBounds
Specifies the clipping rectangle in which the background is drawn.

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.

If the background color of the control is not SystemColors.Control or SystemColors.Transparent, the background is filled with the background color of the control instead. You can force the background to be drawn transparently by using the other overload of DrawBackground.

Example

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