Prev | Current Page 338 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

The MouseButton-
EventArgs class derives from MouseEventArgs (which means it includes the same coordinate
and button state information) and it adds a few members. The less important of these are
MouseButton (which tells you which button triggered the event) and ButtonState (which tells
you whether the button was pressed or unpressed when the event occurred). The more
interesting property is ClickCount, which tells you how many times the button was clicked,
allowing you to distinguish single clicks (where ClickCount is 1) from double-clicks (where
ClickCount is 2).
nTip Usually, Windows applications react when the mouse key is raised after being clicked (the ???up??? event
rather than the ???down??? event).
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 177
Some elements add higher-level mouse events. For example, the Control class adds a
PreviewMouseDoubleClick and MouseDoubleClick event that take the place of the Mouse-
LeftButtonUp event. Similarly, the Button class raises a Click event that can be triggered by the
mouse or keyboard.
nNote As with key press events, the mouse events provide information about where the mouse was and
what buttons were pressed when the mouse event occurred. To get the current mouse position and mouse
button state, you can use the shared members of the Mouse class, which are similar to those of the Mouse-
ButtonEventArgs.


Pages:
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350