Chapter 33

Graphics with GDI+

This is the third of the eight chapters that deal with user interaction and the .NET Framework. Chapter 31, “Windows Forms,” focused on how to display a dialog box or SDI or MDI window, and how to place various controls such as buttons, text boxes, and list boxes. Chapter 32, “Data Binding,” looked at how to work with data in Windows Forms using a number of the Windows Forms controls that work with the disparate data sources that you might encounter.

Although these standard controls are powerful and, by themselves, quite adequate for the complete user interface for many applications, some situations require more flexibility. For example, you might want to draw text in a given font in a precise position in a window, or display images without using a picture box control, or draw simple shapes or other graphics. None of this can be done with the controls discussed in Chapter 31. To display that kind of output, the application must instruct the operating system what to display and where in its window to display it.

Therefore, this chapter shows you how to draw a variety of items including:

  • Principles of drawing
  • Lines and simple shapes
  • BMP images and other image files
  • Text
  • Dealing with printing

In the process, you will need to use a variety of helper objects, including pens (to define the characteristics of lines), brushes (to define how areas are filled in), and fonts (to define the shape of the characters of text). This chapter also goes into some ...

Get Professional C# 2008 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.