Some mouse events

To this point, we have written single and multi-line event handlers. In each of these, the event has been the user clicking on a Button.

However, VB programs can detect and handle many other types of event. Consider for example, this program that handles some TextBox mouse events.

As you see, the program handles three events: the mouse entering the TextBox (MouseEnter), the mouse hovering over the TextBox for a short time (MouseHover), and the mouse leaving the TextBox (MouseLeave). Here is a listing of the three event handlers:

Private Sub txtEventDemo_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEventDemo.MouseEnter
   lblMouseLeave.Visible = False
   lblMouseHover.Visible = False
   lblMouseEnter.Visible = True
End Sub


Private Sub txtEventDemo_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEventDemo.MouseHover
   lblMouseEnter.Visible = False
   lblMouseLeave.Visible = False
   lblMouseHover.Visible = True

End Sub

Private Sub txtEventDemo_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEventDemo.MouseLeave
   lblMouseEnter.Visible = False
   lblMouseHover.Visible = False
   lblMouseLeave.Visible = True
End Sub

Like clicks, these mouse events occur as a result of some user action, While many events in programs are caused by user action, many are generated internally. For example, the initial loading of the program is an event, and there are many other non-user events.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.