ScrollBar.Value 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置表示滚动框在滚动条控件中的当前位置的数值。
public:
 property int Value { int get(); void set(int value); };[System.ComponentModel.Bindable(true)]
public int Value { get; set; }[<System.ComponentModel.Bindable(true)>]
member this.Value : int with get, setPublic Property Value As Integer属性值
处于 Minimum 和 Maximum 范围内的数值。 默认值为 0。
- 属性
例外
示例
以下示例滚动图片框中的图像。 每当用户滚动时,它都使用 Value 滚动条的 来重绘图像的新部分。 此代码示例是为类概述提供的更大示例的 ScrollBar 一部分。
注意
有关如何在 Visual Studio 中运行此示例的说明,请参阅如何:使用 Visual Studio 编译和运行完整的Windows 窗体代码示例。
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;
    }
    g.DrawImage(pictureBox1.Image,
      new Rectangle(0, 0, xWidth, yHeight),  //where to draw the image
      new Rectangle(x, y, xWidth, yHeight),  //the portion of the image to draw
      GraphicsUnit.Pixel);
    pictureBox1.Update();
}
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), _
      GraphicsUnit.Pixel)
    pictureBox1.Update()
End Sub