Partilhar via


TrackBarRenderer.DrawHorizontalTrack(Graphics, Rectangle) Método

Definição

Desenha a barra de uma barra de acompanhamento horizontal com estilos visuais.

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

Parâmetros

g
Graphics

O Graphics usado para desenhar a barra.

bounds
Rectangle

O Rectangle que especifica os limites da barra.

Exceções

O sistema operacional não dá suporte a estilos visuais.

- ou -

Os estilos visuais estão desabilitados pelo usuário no sistema operacional.

- ou -

Os estilos visuais não são aplicados à área de cliente das janelas de aplicativos.

Exemplos

O exemplo de código a seguir usa o DrawHorizontalTrack método em um método de OnPaint controle personalizado para desenhar uma barra de faixa. Este exemplo de código faz parte de um exemplo maior fornecido para a TrackBarRenderer classe.

    // Draw the track bar.
protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        if (!TrackBarRenderer::IsSupported)
        {
            this->Parent->Text = "CustomTrackBar Disabled";
            return;
        }

        this->Parent->Text = "CustomTrackBar Enabled";
        TrackBarRenderer::DrawHorizontalTrack(e->Graphics,
            trackRectangle);
        TrackBarRenderer::DrawTopPointingThumb(e->Graphics,
            thumbRectangle, thumbState);
        TrackBarRenderer::DrawHorizontalTicks(e->Graphics,
            ticksRectangle, numberTicks, EdgeStyle::Raised);
    }

    // Determine whether the user has clicked the track bar thumb.
protected:
    virtual void OnMouseDown(MouseEventArgs^ e) override
    {
        if (!TrackBarRenderer::IsSupported)
        {
            return;
        }
        if (this->thumbRectangle.Contains(e->Location))
        {
            thumbClicked = true;
            thumbState = TrackBarThumbState::Pressed;
        }

        this->Invalidate();
    }
// Draw the track bar.
protected override void OnPaint(PaintEventArgs e)
{
    if (!TrackBarRenderer.IsSupported)
    {
        this.Parent.Text = "CustomTrackBar Disabled";
        return;
    }

    this.Parent.Text = "CustomTrackBar Enabled";
    TrackBarRenderer.DrawHorizontalTrack(e.Graphics,
        trackRectangle);
    TrackBarRenderer.DrawTopPointingThumb(e.Graphics,
        thumbRectangle, thumbState);
    TrackBarRenderer.DrawHorizontalTicks(e.Graphics,
        ticksRectangle, numberTicks, EdgeStyle.Raised);
}

// Determine whether the user has clicked the track bar thumb.
protected override void OnMouseDown(MouseEventArgs e)
{
    if (!TrackBarRenderer.IsSupported)
        return;

    if (this.thumbRectangle.Contains(e.Location))
    {
        thumbClicked = true;
        thumbState = TrackBarThumbState.Pressed;
    }

    this.Invalidate();
}
' Draw the track bar.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    If Not TrackBarRenderer.IsSupported Then
        Me.Parent.Text = "CustomTrackBar Disabled"
        Return
    End If

    Me.Parent.Text = "CustomTrackBar Enabled"
    TrackBarRenderer.DrawHorizontalTrack(e.Graphics, _
        trackRectangle)
    TrackBarRenderer.DrawTopPointingThumb(e.Graphics, _
        thumbRectangle, thumbState)
    TrackBarRenderer.DrawHorizontalTicks(e.Graphics, _
        ticksRectangle, numberTicks, EdgeStyle.Raised)
End Sub

' Determine whether the user has clicked the track bar thumb.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
    If Not TrackBarRenderer.IsSupported Then
        Return
    End If
    If Me.thumbRectangle.Contains(e.Location) Then
        thumbClicked = True
        thumbState = TrackBarThumbState.Pressed
    End If

    Me.Invalidate()
End Sub

Comentários

Antes de chamar esse método, você deve verificar se o valor da IsSupported propriedade é true.

Aplica-se a