Mouse Events

All Control objects support several mouse events, listed in Table 8-2. Three of them—MouseEnter, MouseHover, and MouseLeave—are raised, respectively, every time the mouse cursor goes from being outside to inside the control, stays stationary over a control (or at least does not move outside the control; only a single MouseHover event is raised for every MouseEnter/MouseLeave pair, even if the cursor hovers, moves a bit, then hovers again), or leaves the control's airspace. Each event passes an event argument of type EventArgs, which carries no information about the event. No coordinates are passed, for example. These three events tell you only that the mouse cursor has interacted with a control.

Four low level events, also listed in Table 8-2, pass significant information about the event, in a structure of type MouseEventArgs: MouseDown, MouseMove, MouseWheel, and MouseUp. From the properties of the MouseEventArgs argument, listed in Table 8-3, you can tell which button was pressed on the mouse, and the coordinates of the hot spot of the mouse cursor (relative to the top left corner of the control) when the event was raised, in addition to other information.

Finally, there are two high level events: Click and DoubleClick. These events also take an event argument of type EventArgs, meaning that the event has no additional information. (Additional Control properties, listed in Table 8-5, provide information such as the coordinates and the mouse buttons pressed.) A Click ...

Get Programming .NET Windows Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.