Share via


TrackBarRenderer.GetTopPointingThumbSize(Graphics, TrackBarThumbState) Methode

Definition

Gibt die Größe des nach oben zeigenden Trackleistenschiebereglers, der auch als Ziehpunkt bezeichnet wird, in Pixel zurück.

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

Parameter

g
Graphics

Die Graphics, die von diesem Vorgang verwendet wird.

state
TrackBarThumbState

Einer der TrackBarThumbState-Werte, die den visuellen Zustand des Schiebereglers angeben.

Gibt zurück

Size

Eine Size, die die Größe des Schiebereglers in Pixel angibt.

Ausnahmen

Das Betriebssystem unterstützt keine visuellen Stile.

- oder -

Visuelle Stile wurden durch den Benutzer im Betriebssystem deaktiviert.

- oder -

Visuelle Stile werden nicht auf den Clientbereich der Anwendungsfenster angewendet.

Beispiele

Im folgenden Codebeispiel wird die GetTopPointingThumbSize Methode verwendet, um die Größe des Rechtecks zu bestimmen, das von der DrawTopPointingThumb Methode zum Zeichnen des Schiebereglers verwendet wird. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die TrackBarRenderer Klasse bereitgestellt wird.

    // 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

Hinweise

Die Größe des Schiebereglers wird durch den aktuellen visuellen Stil des Betriebssystems bestimmt.

Bevor Sie diese Methode aufrufen, sollten Sie überprüfen, ob der Wert der IsSupported Eigenschaft ist true.

Gilt für