ScrollBarRenderer.DrawArrowButton 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用视觉样式绘制滚动箭头。
public:
static void DrawArrowButton(System::Drawing::Graphics ^ g, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::ScrollBarArrowButtonState state);
public static void DrawArrowButton (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState state);
static member DrawArrowButton : System.Drawing.Graphics * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState -> unit
Public Shared Sub DrawArrowButton (g As Graphics, bounds As Rectangle, state As ScrollBarArrowButtonState)
参数
ScrollBarArrowButtonState 值之一,指定滚动箭头的可视状态。
例外
示例
下面的代码示例使用 DrawArrowButton 自定义控件 OnPaint 方法中的方法绘制由鼠标指针位置确定的状态中的滚动箭头。 此代码示例是为类提供的大型示例的 ScrollBarRenderer 一部分。
// 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
注解
使用此方法之前,应验证 IsSupported 属性是否返回 true
。