Mouse Input and the WPF - Mouse Input
(Page 2 of 4 )
Mouse input is directed to whichever element is directly under the mouse cursor. All user interface elements derive from the UIElement base class, which defines a number of mouse input events. These are listed in Table 4-1.
Table 4-1. Mouse input events
Event | Routing | Meaning |
GotMouseCapture | Bubble | Element captured the mouse. |
LostMouseCapture | Bubble | Element lost mouse capture. |
MouseEnter | Direct | Mouse pointer moved into element. |
MouseLeave | Direct | Mouse pointer moved out of element. |
PreviewMouseLeftButtonDown, MouseLeftButtonDown | Tunnel, Bubble | Left mouse button pressed while pointer inside element. |
PreviewMouseLeftButtonUp, MouseLeftButtonUp | Tunnel, Bubble | Left mouse button released while pointer inside element. |
PreviewMouseRightButtonDown, MouseRightButtonDown | Tunnel, Bubble | Right mouse button pressed while pointer inside element. |
PreviewMouseRightButtonUp, MouseRightButtonUp | Tunnel, Bubble | Right mouse button released while pointer inside element. |
PreviewMouseDown, MouseDown | Tunnel, Bubble | Mouse button pressed while pointer inside element (raised for any mouse button). |
PreviewMouseUp, MouseUp | Tunnel, Bubble | Mouse button released while pointer inside element (raised for any mouse button). |
PreviewMouseMove, MouseMove | Tunnel, Bubble | Mouse pointer moved while pointer inside element. |
PreviewMouseWheel, MouseWheel | Tunnel, Bubble | Mouse wheel moved while pointer inside element. |
QueryCursor | Bubble | Mouse cursor shape to be determined while pointer inside element. |
In addition to the mouse-related events,UIElementalso defines a pair of properties that indicate whether the mouse pointer is currently over the element:IsMouseOverandIsMouseDirectlyOver. The distinction between these two properties is that the former will be true if the cursor is over the element in question or over any of its child elements, but the latter will be true only if the cursor is over the element in question but not one of its children.
Note that the basic set of mouse events shown in Table 4-1 does not include a Clickevent. This is because clicks are a higher-level concept than basic mouse input—a button can be “clicked” with the mouse, the stylus, the keyboard, or through the Windows accessibility API. Moreover, clicking doesn’t necessarily correspond directly to a single mouse event—usually, the user has to press and release the mouse button while the mouse is over the control to register as a click. Accordingly, these higher-level events are provided by more specialized element types. TheControl class adds aPreviewMouseDoubleClickandMouseDoubleClick event pair. Likewise,ButtonBase—the base class ofButton,CheckBox, andRadioButton—goes on to add aClick event.
Next: Mouse Input and Hit Testing >>
More .NET Articles
More By O'Reilly Media
|
This article is excerpted from Programming WPF, Second Edition, written by Chris Sells and Ian Griffiths (O'Reilly, 2007; ISBN: 0596510373). Check it out today at your favorite bookstore. Buy this book now.
|
|