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, set
Public Property Value As Integer
屬性值
Minimum 及 Maximum 範圍中的數值。 預設值為 0。
- 屬性
例外狀況
範例
下列範例會在圖片方塊中捲動影像。 它會使用 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