Core C# and .NET
< Day Day Up > |
This chapter has focused on using the GDI+ library to display and print text. The first section explained how to create and use font families and font classes. The emphasis was on how to construct fonts and understand the elements that comprise a font by looking at font metrics. After a font has been created, the Graphics.DrawString method is used to draw a text string to a display or printer. Its many overloads permit text to be drawn at specific coordinates or within a rectangular area. By default, text printed in a rectangle is left justified and wrapped to the next line when it hits the bounds of the rectangle. This default formatting can be overridden by passing a StringFormat object to the DrawString method. The StringFormat class is the key to .NET text formatting. It is used to justify text, specify how text is truncated, and set tab stops for creating columnar output. GDI+ provides several classes designed to support printing to a printer. These include the following:
An example for printing a columnar report demonstrated how these classes can be combined to create an application that provides basic report writing. As a final example, we illustrated how the shortcomings of the PrintDocument class can be overcome by creating a custom PrintDocument class that preserves data encapsulation. |
< Day Day Up > |