TrackBarRenderer.GetTopPointingThumbSize(Graphics, TrackBarThumbState) メソッド

定義

上向きのトラック バーのスライダー (つまみとも呼ばれる) のサイズをピクセル単位で返します。

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

パラメーター

g
Graphics

この操作で使用される Graphics

state
TrackBarThumbState

スライダーの表示状態を指定する TrackBarThumbState 値の 1 つ。

戻り値

Size

スライダーのサイズをピクセル単位で指定する Size

例外

オペレーティング システムが visual スタイルをサポートしていません。

または

visual スタイルは、オペレーティング システムのユーザーにより無効にされています。

または

visual スタイルは、アプリケーション ウィンドウのクライアント領域には適用されません。

次のコード例では、メソッドを GetTopPointingThumbSize 使用して、スライダーを描画するためにメソッドで DrawTopPointingThumb 使用される四角形のサイズを決定します。 このコード例は、TrackBarRenderer クラスのために提供されている大規模な例の一部です。

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

注釈

スライダーのサイズは、オペレーティング システムの現在の表示スタイルによって決まります。

このメソッドを呼び出す前に、プロパティtrueIsSupported値が .

適用対象