Mouse Input

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,

Tunnel, Bubble

Left mouse button pressed while pointer inside element.

MouseLeftButtonDown

PreviewMouseLeftButtonUp,

Tunnel, Bubble

Left mouse button released while pointer inside element.

MouseLeftButtonUp

PreviewMouseRightButtonDown,

Tunnel, Bubble

Right mouse button pressed while pointer inside element.

MouseRightButtonDown

PreviewMouseRightButtonUp,

Tunnel, Bubble

Right mouse button released while pointer inside element.

MouseRightButtonUp

PreviewMouseDown,

Tunnel, Bubble

Mouse button pressed while pointer inside element

MouseDown

(raised for any mouse button).

PreviewMouseUp,

Tunnel, Bubble

Mouse button released while pointer inside element

MouseUp

(raised for any mouse button).

PreviewMouseMove,

Tunnel, Bubble

Mouse pointer moved while pointer inside element.

MouseMove

PreviewMouseWheel,

Tunnel, Bubble

Mouse wheel moved while pointer inside element.

MouseWheel

QueryCursor

Bubble

Mouse cursor shape to be determined while pointer

inside element.

inside element.

In addition to the mouse-related events, UIElement also defines a pair of properties that indicate whether the mouse pointer is currently over the element: IsMouseOver and IsMouseDirectlyOver. 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 Click event. 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 higherlevel events are provided by more specialized element types. The Control class adds a PreviewMouseDoubleClick and MouseDoubleClick event pair. Likewise, ButtonBase—the base class of Button, CheckBox, and RadioButton—goes on to add a Click event.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment