ScrollBar.Value Vlastnost

Definice

Získá nebo nastaví číselnou hodnotu, která představuje aktuální pozici posuvníku v ovládacím prvku posuvníku.

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

Hodnota vlastnosti

Int32

Číselná hodnota, která je v rozsahu a Maximum v rozsahuMinimum. Výchozí hodnota je 0.

Atributy

Výjimky

Přiřazená hodnota je menší než Minimum hodnota vlastnosti.

-nebo- Přiřazená hodnota je větší než Maximum hodnota vlastnosti.

Příklady

Následující příklad posune obrázek do pole obrázku. Value Pomocí posuvníku překresluje novou část obrázku pokaždé, když se uživatel posune. Tento příklad kódu je součástí většího příkladu poskytnutého pro ScrollBar přehled třídy.

Poznámka

Pokyny ke spuštění tohoto příkladu v Visual Studio najdete v tématu Postupy: Kompilace a spuštění kompletního příkladu model Windows Forms kódu pomocí 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;
    }

    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

Platí pro