ScrollBar.Scroll Event
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration Public Event Scroll As ScrollEventHandler 'Usage Dim instance As ScrollBar Dim handler As ScrollEventHandler AddHandler instance.Scroll, handler
/** @event */ public void add_Scroll (ScrollEventHandler value) /** @event */ public void remove_Scroll (ScrollEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
For more information about handling events, see Consuming Events.
The following code example uses the derived class VScrollBar. Event handlers for the Scroll and ValueChanged events are created. This code assumes that a Label and Button have been created on a form and that the button has an event handler for the Click event. When the button is clicked, the Value property of the scroll bar is adjusted in code. The label will display the current value of the Value property and the event that changed it. You will notice that when the scroll value is changed by the button's Click event, only the ValueChanged event is raised. In contrast, when the scroll bar is scrolled manually, the Scroll event is raised immediately after the ValueChanged event.
Private Sub AddMyScrollEventHandlers() ' Create and initialize a VScrollBar. Dim vScrollBar1 As New VScrollBar() ' Add event handlers for the OnScroll and OnValueChanged events. AddHandler vScrollBar1.Scroll, AddressOf Me.vScrollBar1_Scroll AddHandler vScrollBar1.ValueChanged, AddressOf Me.vScrollBar1_ValueChanged End Sub ' Create the ValueChanged event handler. Private Sub vScrollBar1_ValueChanged(sender As Object, e As EventArgs) ' Display the new value in the label. label1.Text = "vScrollBar Value:(OnValueChanged Event) " & _ vScrollBar1.Value.ToString() End Sub ' Create the Scroll event handler. Private Sub vScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) ' Display the new value in the label. label1.Text = "VScrollBar Value:(OnScroll Event) " & _ e.NewValue.ToString() End Sub Private Sub button1_Click(sender As Object, e As EventArgs) ' Add 40 to the Value property if it will not exceed the Maximum value. If vScrollBar1.Value + 40 < vScrollBar1.Maximum Then vScrollBar1.Value = vScrollBar1.Value + 40 End If End Sub
private void AddMyScrollEventHandlers()
{
// Create and initialize a VScrollBar.
VScrollBar vScrollBar1 = new VScrollBar();
// Add event handlers for the OnScroll and OnValueChanged events.
vScrollBar1.add_Scroll(
new ScrollEventHandler(this.vScrollBar1_Scroll));
vScrollBar1.add_ValueChanged(
new EventHandler(this.vScrollBar1_ValueChanged));
} //AddMyScrollEventHandlers
// Create the ValueChanged event handler.
private void vScrollBar1_ValueChanged(Object sender, EventArgs e)
{
// Display the new value in the label.
label1.set_Text("vScrollBar Value:(OnValueChanged Event) "
+ vScrollBar1.get_Value());
} //vScrollBar1_ValueChanged
// Create the Scroll event handler.
private void vScrollBar1_Scroll(Object sender, ScrollEventArgs e)
{
// Display the new value in the label.
label1.set_Text(
"VScrollBar Value:(OnScroll Event) " + e.get_NewValue());
} //vScrollBar1_Scroll
private void button1_Click(Object sender, EventArgs e)
{
// Add 40 to the Value property if it will not exceed the Maximum
// value.
if (vScrollBar1.get_Value() + 40 < vScrollBar1.get_Maximum()) {
vScrollBar1.set_Value(vScrollBar1.get_Value() + 40);
}
} //button1_Click
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.