ButtonRenderer.DrawParentBackground(Graphics, Rectangle, Control) Metoda

Definicja

Rysuje tło elementu nadrzędnego kontrolki w określonym obszarze.

public:
 static void DrawParentBackground(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::Control ^ childControl);
public static void DrawParentBackground (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.Control childControl);
static member DrawParentBackground : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.Control -> unit
Public Shared Sub DrawParentBackground (g As Graphics, bounds As Rectangle, childControl As Control)

Parametry

g
Graphics

Używany Graphics do rysowania tła elementu nadrzędnego elementu nadrzędnego .childControl

bounds
Rectangle

Element Rectangle , w którym ma być rysowanie tła kontrolki nadrzędnej. Ten prostokąt powinien znajdować się wewnątrz granic kontrolki podrzędnej.

childControl
Control

Kontrolka, której tło elementu nadrzędnego zostanie narysowane.

Przykłady

Poniższy przykład kodu używa DrawParentBackground metody do malowania obszaru kontrolki niestandardowej. Ten przykład kodu jest częścią większego przykładu podanego ButtonRenderer dla klasy.

    // 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);
        }
    }
// Draw the large or small button, depending on the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.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.
        this.BackColor = Application.RenderWithVisualStyles ?
            Color.Azure : 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);
    }
}
' Draw the large or small button, depending on the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    ' Draw the smaller pressed button image.
    If state = PushButtonState.Pressed Then
        ' 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 Then
            Me.BackColor = Color.Azure
        Else
            Me.BackColor = Me.Parent.BackColor
        End If

        ' 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, _
            Me.ClientRectangle, Me)
        ButtonRenderer.DrawButton(e.Graphics, ClickRectangle, _
            Me.Text, Me.Font, True, state)

    ' Draw the bigger unpressed button image.
    Else
        ButtonRenderer.DrawButton(e.Graphics, Me.ClientRectangle, _
            Me.Text, Me.Font, False, state)
    End If
End Sub

Dotyczy