TrackBarRenderer.GetTopPointingThumbSize(Graphics, TrackBarThumbState) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回指向上方的跟踪条滑块(又称滚动块)的大小,以像素为单位。
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
参数
- state
- TrackBarThumbState
TrackBarThumbState 值之一,指定滑块的可视状态。
返回
一个 Size,以像素为单位指定滑块的大小。
例外
示例
下面的代码示例使用 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
注解
滑块的大小由操作系统的当前视觉样式决定。
在调用此方法之前,应验证属性的值 IsSupported 是否为 true
。