Chapter 14: GDI+

Chapter 14
  • Understanding Windows Forms Geometry
  • Using the Graphics Class
  • Using Color with Windows Forms
  • Using Brushes
  • Drawing with Pens
  • Using Fonts

GDI+ is a new way of drawing graphical images for Microsoft Windows applications. GDI+ improves on the Graphical Device Interface (GDI) included with earlier versions of Windows. Up to now, we’ve been developing the user interface by adding controls to forms; in this chapter, we’ll draw directly on the form, using the methods and properties provided by the Graphics class.

This chapter begins with an examination of Windows Forms geometry, including the Point, Size, and Rectangle structures—three structures that are used to define shapes and locations when programming with Windows Forms. We’ll also look at the Color structure and how it’s used to define the colors used by your application. You’ll also learn how to use Brush objects to fill areas such as rectangles. The Microsoft .NET Framework provides a range of brushes, including brushes used to create gradients and brushes used to fill areas with a pattern from a bitmap. The Graphics class includes methods that enable you to draw lines, figures, and other shapes using a Pen object. Pens can be created in a variety of colors, styles, and patterns, but you can also request a reference to one of the standard pens available through the SystemPens class. We’ll finish up by looking at how the Font class is used to define the fonts used to display text.

Part III: Programming Windows Forms