Chapter 22: Text


Overview

Text is different from the lines, rectangles, ellipses, and other kinds of shapes that a program typically draws. A program normally draws and fills a rectangle in separate steps. On the other hand, a program typically draws text in a single step, usually with a solid color.

Text also differs in the way it is drawn by the GDI+ routines. To draw a line, rectangle, or ellipse, the program specifies the shape’s location, and the GDI+ routines draw it accordingly. Text is not specified by simple location data. A program can specify the text’s general location but has only limited control over its size. Different characters may have different widths in a particular font, so strings containing the same number of characters may have different sizes when displayed.

Even if you know every character’s nominal size, you may not be able to add them up to calculate the size of a string. Fonts sometimes use special algorithms that adjust the spacing between certain pairs of letters to make the result look better. For example, a font might decrease the spacing between the characters A and W when they appear next to each other (as in AW) to allow the W to lean over the A.

This chapter describes some of the tools that Visual Basic provides for controlling text. It explains how to draw text aligned and formatted in various ways, and how to measure text so that you can figure out more exactly where it will appear.

Note that several examples use the Graphics object’s TextRenderingHint property to make text appear smoother. For more information on this property, see the section “System.Drawing.Text” in Chapter 20.

Tip 

Note that Windows Vista uses a slightly different underlying graphics model than previous versions of Windows. In particular, Vista has made some changes to produce better-looking, smoother text. Microsoft has worked to make the Vista graphics system compatible with GDI+, but you might encounter some small differences or glitches. For some additional information about the underlying graphics system, see the article “Graphics APIs in Windows Vista” at msdn2.microsoft.com/library/bb173477.aspx.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net