Share via


TrackBarRenderer.GetTopPointingThumbSize(Graphics, TrackBarThumbState) Método

Definición

Devuelve el tamaño, en píxeles, del control deslizante de barra de seguimiento (denominado también control de posición) que señala hacia arriba.

public:
 static System::Drawing::Size GetTopPointingThumbSize(System::Drawing::Graphics ^ g, System::Windows::Forms::VisualStyles::TrackBarThumbState state);
public static System.Drawing.Size GetTopPointingThumbSize (System.Drawing.Graphics g, System.Windows.Forms.VisualStyles.TrackBarThumbState state);
static member GetTopPointingThumbSize : System.Drawing.Graphics * System.Windows.Forms.VisualStyles.TrackBarThumbState -> System.Drawing.Size
Public Shared Function GetTopPointingThumbSize (g As Graphics, state As TrackBarThumbState) As Size

Parámetros

g
Graphics

Objeto Graphics que va a utilizar esta operación.

state
TrackBarThumbState

Uno de los valores de TrackBarThumbState que especifica el estado visual del control deslizante.

Devoluciones

Size

Un objeto Size que especifica el tamaño, en píxeles, del control deslizante.

Excepciones

El sistema operativo no admite estilos visuales.

o bien

El usuario ha deshabilitado los estilos visuales en el sistema operativo.

o bien

Los estilos visuales no se aplican al área de cliente de las ventanas de aplicación.

Ejemplos

En el ejemplo de código siguiente se usa el GetTopPointingThumbSize método para determinar el tamaño del rectángulo utilizado por el DrawTopPointingThumb método para dibujar el control deslizante. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la TrackBarRenderer clase .

    // Calculate the sizes of the bar, thumb, and ticks rectangle.
private:
    void SetupTrackBar()
    {
        if (!TrackBarRenderer::IsSupported)
        {
            return;
        }

        Graphics^ g = this->CreateGraphics();

        // Calculate the size of the track bar.
        trackRectangle.X = ClientRectangle.X + 2;
        trackRectangle.Y = ClientRectangle.Y + 28;
        trackRectangle.Width = ClientRectangle.Width - 4;
        trackRectangle.Height = 4;

        // Calculate the size of the rectangle in which to
        // draw the ticks.
        ticksRectangle.X = trackRectangle.X + 4;
        ticksRectangle.Y = trackRectangle.Y - 8;
        ticksRectangle.Width = trackRectangle.Width - 8;
        ticksRectangle.Height = 4;

        tickSpace = ((float)ticksRectangle.Width - 1) /
            ((float)numberTicks - 1);

        // Calculate the size of the thumb.
        thumbRectangle.Size =
            TrackBarRenderer::GetTopPointingThumbSize(g,
            TrackBarThumbState::Normal);

        thumbRectangle.X = CurrentTickXCoordinate();
        thumbRectangle.Y = trackRectangle.Y - 8;
    }
// Calculate the sizes of the bar, thumb, and ticks rectangle.
private void SetupTrackBar()
{
    if (!TrackBarRenderer.IsSupported)
        return;

    using (Graphics g = this.CreateGraphics())
    {
        // Calculate the size of the track bar.
        trackRectangle.X = ClientRectangle.X + 2;
        trackRectangle.Y = ClientRectangle.Y + 28;
        trackRectangle.Width = ClientRectangle.Width - 4;
        trackRectangle.Height = 4;

        // Calculate the size of the rectangle in which to 
        // draw the ticks.
        ticksRectangle.X = trackRectangle.X + 4;
        ticksRectangle.Y = trackRectangle.Y - 8;
        ticksRectangle.Width = trackRectangle.Width - 8;
        ticksRectangle.Height = 4;

        tickSpace = ((float)ticksRectangle.Width - 1) /
            ((float)numberTicks - 1);

        // Calculate the size of the thumb.
        thumbRectangle.Size =
            TrackBarRenderer.GetTopPointingThumbSize(g,
            TrackBarThumbState.Normal);

        thumbRectangle.X = CurrentTickXCoordinate();
        thumbRectangle.Y = trackRectangle.Y - 8;
    }
}
' Calculate the sizes of the bar, thumb, and ticks rectangle.
Private Sub SetupTrackBar()
    If Not TrackBarRenderer.IsSupported Then
        Return
    End If
    Using g As Graphics = Me.CreateGraphics()
        ' Calculate the size of the track bar.
        trackRectangle.X = ClientRectangle.X + 2
        trackRectangle.Y = ClientRectangle.Y + 28
        trackRectangle.Width = ClientRectangle.Width - 4
        trackRectangle.Height = 4

        ' Calculate the size of the rectangle in which to 
        ' draw the ticks.
        ticksRectangle.X = trackRectangle.X + 4
        ticksRectangle.Y = trackRectangle.Y - 8
        ticksRectangle.Width = trackRectangle.Width - 8
        ticksRectangle.Height = 4

        tickSpace = (CSng(ticksRectangle.Width) - 1) / _
            (CSng(numberTicks) - 1)

        ' Calculate the size of the thumb.
        thumbRectangle.Size = _
            TrackBarRenderer.GetTopPointingThumbSize( _
            g, TrackBarThumbState.Normal)

        thumbRectangle.X = CurrentTickXCoordinate()
        thumbRectangle.Y = trackRectangle.Y - 8
    End Using
End Sub

Comentarios

El tamaño del control deslizante viene determinado por el estilo visual actual del sistema operativo.

Antes de llamar a este método, debe comprobar que el valor de la IsSupported propiedad es true.

Se aplica a