Chapter 5. GDI+ and Drawing

In the previous chapter, you created custom controls by combining already existing controls. As noted in that chapter, there are times when you want to take over the entire responsibility of drawing a custom control. In fact, there are times when you want to take over the entire display on a form.

To do so, you'll need the tools made available through GDI+ and the Graphics class.

Tip

The GDI+-managed class interface is part of the Microsoft .NET Framework and is implemented as a set of wrappers over Windows objects.

The control you will create is shown in Figure 5-1.

Clock Face Custom Control

Figure 5-1. Clock Face Custom Control

To begin, right-click on NorthWindControls and choose Add → New Item. In the Add New Item dialog box, choose Custom Control and name your new Custom Control ClockFaceCtrl.vb. Switch to code view, since you'll be creating this control entirely through code, from scratch.

To create this control, you will be responsible for every aspect of drawing the clock and animating it. To simplify your coding, you'll want to add an Imports statement for the Drawing namespace:

Imports System.Drawing

The Drawing namespace includes a number of classes and structures that we'll use in this program. Some of the most important members of this class are summarized briefly in Table 5-1.

Table 5-1. Members of the Drawing class

Class

Description

Bitmap

Encapsulates a GDI+ ...

Get Programming Visual Basic 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.