Raises the System.WinForms.ScrollBar.ValueChanged event.
[Visual Basic] Overridable Protected Sub OnValueChanged( _ ByVal e As EventArgs _ ) [C#] protected virtual void OnValueChanged( EventArgs e ); [C++] protected: virtual void OnValueChanged( EventArgs* e ); [JScript] protected function OnValueChanged( e : EventArgs );
The following example uses the derived class, VScrollBar. Event handlers for the System.WinForms.ScrollBar.Scroll and System.WinForms.ScrollBar.ValueChanged events are created. This code assumes that a Label and Button have been instantiated on a form and the button has an event handler for the System.WinForms.Control.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.
[Visual Basic]
Private Sub MySub() ' Initialize the VScrollBar. Set Me.VScrollBar1 = New System.WinForms.VScrollBar ' Add event handlers for the OnScroll and OnValueChanged events. VScrollBar1.AddOnScroll New System.WinForms.ScrollEventHandler _ (AddressOf Me.VScrollBar1_Scroll) VScrollBar1.AddOnValueChanged New System.EventHandler _ (AddressOf Me.VScrollBar1_ValueChanged) End Sub ' ValueChanged event handler. Private Sub VScrollBar1_ValueChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) 'Display the new value in the label. Label1.Text = "VScrollBar Value:(OnValueChanged Event) " & CStr(VScrollBar1.Value) End Sub ' Scroll event handler. Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.WinForms.ScrollEvent) ' Display the new value in the label. Label1.Text = "VScrollBar Value:(OnScroll Event) " & CStr(VScrollBar1.Value) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Add 40 to the scroll bar value if it will not exceed the Maximum value. If VScrollBar1.Value + 40 < VScrollBar1.Maximum Then VScrollBar1.Value = VScrollBar1.Value + 40 End If End Sub
ScrollBar Class | ScrollBar Members | System.WinForms Namespace