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
Control class supports two related events:
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
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.
To get started, you’ll need to change ...