ScrollBarRenderer.DrawLeftHorizontalTrack Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Rysuje poziomą ścieżkę paska przewijania ze stylami wizualnymi.
public:
static void DrawLeftHorizontalTrack(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::ScrollBarState state);
public static void DrawLeftHorizontalTrack (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ScrollBarState state);
static member DrawLeftHorizontalTrack : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.ScrollBarState -> unit
Public Shared Sub DrawLeftHorizontalTrack (g As Graphics, bounds As Rectangle, state As ScrollBarState)
Parametry
- state
- ScrollBarState
ScrollBarState Jedna z wartości określających stan wizualny ścieżki paska przewijania.
Wyjątki
System operacyjny nie obsługuje stylów wizualnych.
-lub-
Style wizualizacji są wyłączone przez użytkownika w systemie operacyjnym.
-lub-
Style wizualne nie są stosowane do obszaru klienta okien aplikacji.
Przykłady
W poniższym przykładzie DrawLeftHorizontalTrack kodu użyto metody w metodzie kontrolki OnPaint niestandardowej, aby narysować lewą stronę ścieżki paska przewijania w stanie naciśniętym. Ten przykład kodu jest częścią większego przykładu udostępnionego ScrollBarRenderer dla klasy .
// Draw the scroll bar in its normal state.
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
__super::OnPaint(e);
// Visual styles are not enabled.
if (!ScrollBarRenderer::IsSupported)
{
this->Parent->Text = "CustomScrollBar Disabled";
return;
}
this->Parent->Text = "CustomScrollBar Enabled";
// Draw the scroll bar track.
ScrollBarRenderer::DrawRightHorizontalTrack(e->Graphics,
ClientRectangle, ScrollBarState::Normal);
// Draw the thumb and thumb grip in the current state.
ScrollBarRenderer::DrawHorizontalThumb(e->Graphics,
thumbRectangle, thumbState);
ScrollBarRenderer::DrawHorizontalThumbGrip(e->Graphics,
thumbRectangle, thumbState);
// Draw the scroll arrows in the current state.
ScrollBarRenderer::DrawArrowButton(e->Graphics,
leftArrowRectangle, leftButtonState);
ScrollBarRenderer::DrawArrowButton(e->Graphics,
rightArrowRectangle, rightButtonState);
// Draw a highlighted rectangle in the left side of the scroll
// bar track if the user has clicked between the left arrow
// and thumb.
if (leftBarClicked)
{
clickedBarRectangle.X = thumbLeftLimit;
clickedBarRectangle.Width = thumbRectangle.X - thumbLeftLimit;
ScrollBarRenderer::DrawLeftHorizontalTrack(e->Graphics,
clickedBarRectangle, ScrollBarState::Pressed);
}
// Draw a highlighted rectangle in the right side of the scroll
// bar track if the user has clicked between the right arrow
// and thumb.
else if (rightBarClicked)
{
clickedBarRectangle.X =
thumbRectangle.X + thumbRectangle.Width;
clickedBarRectangle.Width =
thumbRightLimitRight - clickedBarRectangle.X;
ScrollBarRenderer::DrawRightHorizontalTrack(e->Graphics,
clickedBarRectangle, ScrollBarState::Pressed);
}
}
// Draw the scroll bar in its normal state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Visual styles are not enabled.
if (!ScrollBarRenderer.IsSupported)
{
this.Parent.Text = "CustomScrollBar Disabled";
return;
}
this.Parent.Text = "CustomScrollBar Enabled";
// Draw the scroll bar track.
ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics,
ClientRectangle, ScrollBarState.Normal);
// Draw the thumb and thumb grip in the current state.
ScrollBarRenderer.DrawHorizontalThumb(e.Graphics,
thumbRectangle, thumbState);
ScrollBarRenderer.DrawHorizontalThumbGrip(e.Graphics,
thumbRectangle, thumbState);
// Draw the scroll arrows in the current state.
ScrollBarRenderer.DrawArrowButton(e.Graphics,
leftArrowRectangle, leftButtonState);
ScrollBarRenderer.DrawArrowButton(e.Graphics,
rightArrowRectangle, rightButtonState);
// Draw a highlighted rectangle in the left side of the scroll
// bar track if the user has clicked between the left arrow
// and thumb.
if (leftBarClicked)
{
clickedBarRectangle.X = thumbLeftLimit;
clickedBarRectangle.Width = thumbRectangle.X - thumbLeftLimit;
ScrollBarRenderer.DrawLeftHorizontalTrack(e.Graphics,
clickedBarRectangle, ScrollBarState.Pressed);
}
// Draw a highlighted rectangle in the right side of the scroll
// bar track if the user has clicked between the right arrow
// and thumb.
else if (rightBarClicked)
{
clickedBarRectangle.X =
thumbRectangle.X + thumbRectangle.Width;
clickedBarRectangle.Width =
thumbRightLimitRight - clickedBarRectangle.X;
ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics,
clickedBarRectangle, ScrollBarState.Pressed);
}
}
' Draw the scroll bar in its normal state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
' Visual styles are not enabled.
If Not ScrollBarRenderer.IsSupported Then
Me.Parent.Text = "CustomScrollBar Disabled"
Return
End If
Me.Parent.Text = "CustomScrollBar Enabled"
' Draw the scroll bar track.
ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics, _
Me.ClientRectangle, ScrollBarState.Normal)
' Draw the thumb and thumb grip in the current state.
ScrollBarRenderer.DrawHorizontalThumb(e.Graphics, _
thumbRectangle, thumbState)
ScrollBarRenderer.DrawHorizontalThumbGrip(e.Graphics, _
thumbRectangle, thumbState)
' Draw the scroll arrows in the current state.
ScrollBarRenderer.DrawArrowButton(e.Graphics, _
leftArrowRectangle, leftButtonState)
ScrollBarRenderer.DrawArrowButton(e.Graphics, _
rightArrowRectangle, rightButtonState)
' Draw a highlighted rectangle in the left side of the scroll
' bar track if the user has clicked between the left arrow
' and thumb.
If leftBarClicked Then
clickedBarRectangle.X = thumbLeftLimit
clickedBarRectangle.Width = thumbRectangle.X - thumbLeftLimit
ScrollBarRenderer.DrawLeftHorizontalTrack(e.Graphics, _
clickedBarRectangle, ScrollBarState.Pressed)
' Draw a highlighted rectangle in the right side of the scroll
' bar track if the user has clicked between the right arrow
' and thumb.
ElseIf rightBarClicked Then
clickedBarRectangle.X = thumbRectangle.X + _
thumbRectangle.Width
clickedBarRectangle.Width = thumbRightLimitRight - _
clickedBarRectangle.X
ScrollBarRenderer.DrawRightHorizontalTrack(e.Graphics, _
clickedBarRectangle, ScrollBarState.Pressed)
End If
End Sub
Uwagi
Przed użyciem tej metody należy sprawdzić, czy IsSupported właściwość zwraca wartość true
.