- Investigating Unsupported Controls in the .NET Compact Framework
- Investigating Unsupported System.Windows.Forms Functionality in the .NET Compact Framework
- Working with the Visual Studio .NET Form Designer
- Understanding the Different Windows Forms Target Platforms
- Working with the Form Control
- Programming the Button Control
- Using the TextBox Control
- Using the Label Control
- Working with RadioButton Controls
- Using the CheckBox Control
- Using the ComboBox Control
- Using the ListBox Control
- Using the NumericUpDown Control
- Using the DomainUpDown Control
- Programming the ProgressBar Control
- Using the StatusBar Control
- Using the TrackBar Control
- Using the ToolBar Control
- Adding Menus with the MainMenu Control
- Using a ContextMenu Control in an Application
- Using the Timer Control
- Using the OpenFileDialog and SaveFileDialog Controls
- Using the Panel Control
- Using the HScrollBar and VScrollBar Controls
- Using the ImageList Control
- Using the PictureBox Control
- Using the ListView Control
- Using the TabControl Control
- Using the TreeView Control
- Working with the DataGrid Control
- In Brief
Using the HScrollBar and VScrollBar Controls
The HScrollBar and VScrollBar controls allow you to add scrolling capabilities to components that do not support scrolling by default. The controls are driven by several properties. The following list contains these properties and their meanings.
Minimum The value of the control when the scroll thumb is at the left end of the HScrollBar or top of the VScrollBar.
Maximum This is the largest possible value of the scroll bar. Note that the Value property of the scroll bar when the thumb is pulled all the way to the right for the HScrollBar or the bottom of the VScrollBar is not equal to the Maximum property. The Value property will be equal to this formula: Maximum LargeChange + 1.
SmallChange Here's the increment value used when the user clicks one of the arrow buttons.
LargeChange This is the increment value used when the user clicks the scroll bar control on either side of the scroll thumb.
Value The current value of the scroll bar. This value represents the position of the top of the HScrollBar's scroll thumb and the left side of the VScrollBar's scroll thumb.
A ValueChanged event is fired when the Value property changes. Trap this event to perform some action, such as change the position of a control, when the scroll bar's value changes. The following code demonstrates how to handle the ValueChanges event:
C# private void hScrollBar1_ValueChanged(object sender, System.EventArgs e) { this.label1.Text = string.Format("Scroll Bar Value: {0}", this.hScrollBar1.Value); } VB Private Sub hScrollBar1_ValueChanged(object sender, System.EventArgs e) _Handles hScrollBar1.ValueChanged Me.label1.Text = string.Format("Scroll Bar Value: {0}", this.hScrollBar1.Value) End Sub
Figure 3.21 shows an application with a HScrollBar control linked to a Label control. The Label control displays the Value of the HScrollBar. When you move the scroll bar, the label is updated with the new value. In this sample the Minimum is 0, the Maximum is 100, SmallChange is 10, and LargeChange is 20. The complete code for this sample can be found in the code list for this book.
Figure 3.21 A Sample Application Showcasing the HScrollBar.