ScrollBar.Value Özellik

Tanım

Kaydırma çubuğu denetimindeki kaydırma kutusunun geçerli konumunu temsil eden sayısal bir değer alır veya ayarlar.

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

Özellik Değeri

Int32

ve Maximum aralığındaki Minimum sayısal değer. Varsayılan değer 0’dır.

Öznitelikler

Özel durumlar

Atanan değer özellik değerinden Minimum küçük.

-veya- Atanan değer özellik değerinden Maximum büyük.

Örnekler

Aşağıdaki örnek, resim kutusundaki bir resmi kaydırıyor. Kullanıcı her kaydırışında Value görüntünün yeni bir bölümünü yeniden çizmek için kaydırma çubuğunun öğesini kullanır. Bu kod örneği, sınıfa genel bakış için ScrollBar sağlanan daha büyük bir örneğin parçasıdır.

Not

Bu örneği Visual Studio'de çalıştırma hakkında yönergeler için bkz. Nasıl yapılır: Visual Studio Kullanarak Eksiksiz bir Windows Forms Kod Örneği Derleme ve Çalıştırma.

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

Şunlara uygulanır