ButtonRenderer::DrawParentBackground Method (Graphics^, Rectangle, Control^)

 

Draws the background of a control's parent in the specified area.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
static void DrawParentBackground(
	Graphics^ g,
	Rectangle bounds,
	Control^ childControl
)

Parameters

g
Type: System.Drawing::Graphics^

The Graphics used to draw the background of the parent of childControl.

bounds
Type: System.Drawing::Rectangle

The Rectangle in which to draw the parent control's background. This rectangle should be inside the child control’s bounds.

childControl
Type: System.Windows.Forms::Control^

The control whose parent's background will be drawn.

The following code example uses the DrawParentBackground method to paint over an area of a custom control. This code example is part of a larger example provided for the ButtonRenderer class.

    // Draw the large or small button, depending on the current state.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        __super::OnPaint(e);

        // Draw the smaller pressed button image
        if (state == PushButtonState::Pressed)
        {
            // Set the background color to the parent if visual styles
            // are disabled, because DrawParentBackground will only paint
            // over the control background if visual styles are enabled.
            if (Application::RenderWithVisualStyles)
            {
                this->BackColor = Color::Azure;
            }
            else
            {
                this->BackColor = this->Parent->BackColor;
            }


            // If you comment out the call to DrawParentBackground,
            // the background of the control will still be visible
            // outside the pressed button, if visual styles are enabled.
            ButtonRenderer::DrawParentBackground(e->Graphics,
                ClientRectangle, this);
            ButtonRenderer::DrawButton(e->Graphics, ClickRectangle,
                this->Text, this->Font, true, state);
        }

        // Draw the bigger unpressed button image.
        else
        {
            ButtonRenderer::DrawButton(e->Graphics, ClientRectangle,
                this->Text, this->Font, false, state);
        }
    }

.NET Framework
Available since 2.0
Return to top
Show: