ScrollBar.Value ScrollBar.Value ScrollBar.Value ScrollBar.Value Property


获取或设置表示滚动框在滚动条控件中的当前位置的数值。Gets or sets a numeric value that represents the current position of the scroll box on the scroll bar control.

 property int Value { int get(); void set(int value); };
public int Value { get; set; }
member this.Value : int with get, set
Public Property Value As Integer


处于 MinimumMaximum 范围内的数值。A numeric value that is within the Minimum and Maximum range. 默认值为 0。The default value is 0.


所赋的值小于 Minimum 属性值。The assigned value is less than the Minimum property value.

-or- 所赋的值大于 Maximum 属性值。The assigned value is greater than the Maximum property value.


以下示例滚动图片框中的图像。The following example scrolls an image in a picture box. 当用户滚动Value时,它将使用滚动条的来重绘图像的新部分。It uses the Value of the scrollbar to redraw a new part of the image whenever the user scrolls. 此代码示例是为ScrollBar类概述提供的更大示例的一部分。This code example is part of a larger example provided for the ScrollBar class overview.


有关如何在 Visual Studio 中运行此示例的说明,请参阅如何:使用 Visual Studio编译和运行完整的 Windows 窗体代码示例。For instructions about how to run this example in Visual Studio, see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.

private void HandleScroll(Object sender, ScrollEventArgs e)
    //Create a graphics object and draw a portion of the image in the PictureBox.
    Graphics g = pictureBox1.CreateGraphics();

    int xWidth = pictureBox1.Width;
    int yHeight = pictureBox1.Height;

    int x;
    int y;

    if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
        x = e.NewValue;
        y = vScrollBar1.Value;
    else //e.ScrollOrientation == ScrollOrientation.VerticalScroll
        y = e.NewValue;
        x = hScrollBar1.Value;

      new Rectangle(0, 0, xWidth, yHeight),  //where to draw the image
      new Rectangle(x, y, xWidth, yHeight),  //the portion of the image to draw

Private Sub HandleScroll(ByVal sender As [Object], ByVal e As ScrollEventArgs) _
  Handles vScrollBar1.Scroll, hScrollBar1.Scroll

    'Create a graphics object and draw a portion of the image in the PictureBox.
    Dim g As Graphics = pictureBox1.CreateGraphics()

    Dim xWidth As Integer = pictureBox1.Width
    Dim yHeight As Integer = pictureBox1.Height

    Dim x As Integer
    Dim y As Integer

    If (e.ScrollOrientation = ScrollOrientation.HorizontalScroll) Then

        x = e.NewValue
        y = vScrollBar1.Value

    Else 'e.ScrollOrientation == ScrollOrientation.VerticalScroll

        y = e.NewValue
        x = hScrollBar1.Value
    End If

    'First Rectangle: Where to draw the image.
    'Second Rectangle: The portion of the image to draw.

    g.DrawImage(pictureBox1.Image, _
      New Rectangle(0, 0, xWidth, yHeight), _
      New Rectangle(x, y, xWidth, yHeight), _

End Sub