ScrollBar.SmallChange Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur nilai yang akan ditambahkan atau dikurangi dari Value properti saat kotak gulir dipindahkan dengan jarak yang kecil.
public:
property int SmallChange { int get(); void set(int value); };
public int SmallChange { get; set; }
member this.SmallChange : int with get, set
Public Property SmallChange As Integer
Nilai Properti
Nilai numerik. Nilai defaultnya adalah 1.
Pengecualian
Nilai yang ditetapkan kurang dari 0.
Contoh
Contoh berikut mengasumsikan bahwa Anda telah membuat Form, menambahkan PictureBox ke Form, dan menambahkan horizontal HScrollBar dan vertikal VScrollBar ke PictureBox. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ScrollBar gambaran umum kelas.
Dalam contoh ini, SmallChange properti diatur relatif terhadap ukuran PictureBox.
Anda harus menambahkan referensi ke System.Drawing namespace layanan dan System.Windows.Forms untuk menjalankan contoh ini.
Nota
Untuk petunjuk tentang cara menjalankan contoh ini di Visual Studio, lihat Cara: Mengkompilasi dan Menjalankan Contoh Kode Formulir Windows Lengkap Menggunakan Visual Studio.
public void SetScrollBarValues()
{
//Set the following scrollbar properties:
//Minimum: Set to 0
//SmallChange and LargeChange: Per UI guidelines, these must be set
// relative to the size of the view that the user sees, not to
// the total size including the unseen part. In this example,
// these must be set relative to the picture box, not to the image.
//Maximum: Calculate in steps:
//Step 1: The maximum to scroll is the size of the unseen part.
//Step 2: Add the size of visible scrollbars if necessary.
//Step 3: Add an adjustment factor of ScrollBar.LargeChange.
//Configure the horizontal scrollbar
//---------------------------------------------
if (this.hScrollBar1.Visible)
{
this.hScrollBar1.Minimum = 0;
this.hScrollBar1.SmallChange = this.pictureBox1.Width / 20;
this.hScrollBar1.LargeChange = this.pictureBox1.Width / 10;
this.hScrollBar1.Maximum = this.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width; //step 1
if (this.vScrollBar1.Visible) //step 2
{
this.hScrollBar1.Maximum += this.vScrollBar1.Width;
}
this.hScrollBar1.Maximum += this.hScrollBar1.LargeChange; //step 3
}
//Configure the vertical scrollbar
//---------------------------------------------
if (this.vScrollBar1.Visible)
{
this.vScrollBar1.Minimum = 0;
this.vScrollBar1.SmallChange = this.pictureBox1.Height / 20;
this.vScrollBar1.LargeChange = this.pictureBox1.Height / 10;
this.vScrollBar1.Maximum = this.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height; //step 1
if (this.hScrollBar1.Visible) //step 2
{
this.vScrollBar1.Maximum += this.hScrollBar1.Height;
}
this.vScrollBar1.Maximum += this.vScrollBar1.LargeChange; //step 3
}
}
Public Sub SetScrollBarValues()
'Set the following scrollbar properties:
'Minimum: Set to 0
'SmallChange and LargeChange: Per UI guidelines, these must be set
' relative to the size of the view that the user sees, not to
' the total size including the unseen part. In this example,
' these must be set relative to the picture box, not to the image.
'Maximum: Calculate in steps:
'Step 1: The maximum to scroll is the size of the unseen part.
'Step 2: Add the size of visible scrollbars if necessary.
'Step 3: Add an adjustment factor of ScrollBar.LargeChange.
'Configure the horizontal scrollbar
'---------------------------------------------
If (Me.hScrollBar1.Visible) Then
Me.hScrollBar1.Minimum = 0
Me.hScrollBar1.SmallChange = CInt(Me.pictureBox1.Width / 20)
Me.hScrollBar1.LargeChange = CInt(Me.pictureBox1.Width / 10)
Me.hScrollBar1.Maximum = Me.pictureBox1.Image.Size.Width - pictureBox1.ClientSize.Width 'step 1
If (Me.vScrollBar1.Visible) Then 'step 2
Me.hScrollBar1.Maximum += Me.vScrollBar1.Width
End If
Me.hScrollBar1.Maximum += Me.hScrollBar1.LargeChange 'step 3
End If
'Configure the vertical scrollbar
'---------------------------------------------
If (Me.vScrollBar1.Visible) Then
Me.vScrollBar1.Minimum = 0
Me.vScrollBar1.SmallChange = CInt(Me.pictureBox1.Height / 20)
Me.vScrollBar1.LargeChange = CInt(Me.pictureBox1.Height / 10)
Me.vScrollBar1.Maximum = Me.pictureBox1.Image.Size.Height - pictureBox1.ClientSize.Height 'step 1
If (Me.hScrollBar1.Visible) Then 'step 2
Me.vScrollBar1.Maximum += Me.hScrollBar1.Height
End If
Me.vScrollBar1.Maximum += Me.vScrollBar1.LargeChange 'step 3
End If
End Sub
Keterangan
Saat pengguna menekan salah satu tombol panah atau mengklik salah satu tombol bilah gulir, Value properti berubah sesuai dengan nilai yang SmallChange diatur dalam properti .
Panduan antarmuka pengguna menyarankan bahwa SmallChange properti dan LargeChange diatur relatif terhadap ukuran tampilan yang dilihat pengguna, bukan ke ukuran total termasuk bagian yang tidak terlihat. Misalnya, jika Anda memiliki kotak gambar dengan bilah gulir yang menampilkan gambar besar, SmallChange properti dan LargeChange harus diatur relatif terhadap ukuran kotak gambar, bukan ke ukuran gambar.