ScrollBar.Value 속성

정의

scroll bar 컨트롤에 있는 스크롤 상자의 현재 위치를 나타내는 숫자 값을 가져오거나 설정합니다.

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, set
Public Property Value As Integer

속성 값

Int32

Minimum에서 Maximum 범위 사이의 숫자 값으로, 기본값은 0입니다.

특성

예외

할당된 값이 Minimum 속성 값보다 작은 경우

또는 할당된 값이 Maximum 속성 값보다 큰 경우

예제

다음은 그림 상자에서 이미지를 스크롤하는 예제입니다. 사용자가 스크롤할 때마다 스크롤 막대를 사용하여 이미지의 새 부분을 다시 그리는 데 사용됩니다 Value . 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ScrollBar 클래스 개요입니다.

참고

Visual Studio 이 예제를 실행하는 방법에 대한 지침은 방법: Visual Studio 사용하여 전체 Windows Forms 코드 예제 컴파일 및 실행을 참조하세요.

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

적용 대상