As handy as forms are, especially when laden with controls, sometimes the built-in controls [1] aren't sufficient to render the state of your application. In that case, you need to draw the state yourself. The drawing may be to the screen, to a file, or to a printer, but wherever you're drawing to, you'll be dealing with the same primitives ”colors, brushes, pens, and fonts ”and the same kinds of things to draw: shapes , images, and strings. This chapter starts by examining the basics of drawing to the screen and the basic building blocks of drawing.
Note that all the drawing techniques discussed in this chapter and in the next two chapters relate equally as well to controls as they do to forms. For information about building custom controls, see Chapter 8: Controls. One more thing worth noting before we begin is that the System.Drawing namespace is implemented on top of GDI+ (Graphics Device Interface+), the successor to GDI. The original GDI has been a mainstay in Windows since there was a Windows, providing an abstraction over screens and printers to make writing GUI-style applications easy. [2] GDI+ is a Win32 DLL (gdiplus.dll) that ships with Windows XP and is available for older versions of Windows. GDI+ is also an unmanaged C++ class library that wraps gdiplus.dll. Because the System.Drawing classes share many of the same names with the GDI+ C++ classes, you may very well stumble onto the unmanaged classes when looking for the .NET classes in the online documentation. The concepts are the same, but the coding details are very different between unmanaged C++ and managed anything else, so keep an eye out.
|