Capturing the Mouse
Ordinarily, every time an element receives a mouse button ???down??? event, it will receive a corresponding
mouse button ???up??? event shortly thereafter. However, this isn??™t always the case. For
example, if you click an element, hold down the mouse, and then move the mouse pointer off
the element, the element won??™t receive the mouse up event.
In some situations, you may want to have a notification of mouse up events, even if they
occur after the mouse has moved off your element. To do so, you need to capture the mouse by
calling the Mouse.Capture() method and passing in the appropriate element. From that point
on, you??™ll receive mouse down and mouse up events until you call Mouse.Capture() again and
pass in a null reference (Nothing). Other elements won??™t receive mouse events while the
mouse is captured. That means the user won??™t be able to click buttons elsewhere in the window,
click inside text boxes, and so on. Mouse capturing is sometimes used to implement
draggable and resizable elements. You??™ll see an example with the custom drawn resizable
window in Chapter 8.
nTip When you call Mouse.Capture() you can pass in an optional CaptureMode value as the second parameter.
Ordinarily, when you call Mouse.Capture() you use CaptureMode.Element, which means your element
always receives the mouse events.
Pages:
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351