Chapter 6. Mice and Fonts


In the previous chapter, you created a custom control from scratch, and placed it in a form. In this chapter, you'll have the clock control that you created respond to mouse events and you'll allow the user to set the clock's fonts.

Every control supports several mouse events, including MouseClick, DoubleClick, MouseEnter, MouseHover, MouseLeave, MouseDown, MouseMove, MouseWheel, and MouseUp.

The base Control class supports two related events: Click and MouseClick. Click will be fired any time the control is clicked (e.g., by tabbing to it and pressing spacebar or by clicking with the mouse) while MouseClick will only fire if the control is clicked with the mouse.


To test these, we'll add the following behavior:

  • When the user clicks in the control, we'll center the clock on that click point.

  • When the user presses the mouse button, we'll change the cursor to a hand, at the click point.

  • When the user drags the clock (with the mouse button down), we'll move the clock, centered on the mouse location.

  • When the user lets up the mouse button, we'll change the cursor back to default and leave the clock at the location of the MouseUp.

  • When the mouse enters our control, we'll set the background color to light blue.

  • When the mouse leaves our control, we'll restore its default background color.

The net effect is that the user can click on a new location to move the clock, or the user can drag the clock to the new location.



Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net