logo
CSharp_Graphics

Компиляция кода

Предыдущий пример предназначен для работы с Windows Forms, для него необходим объект PaintEventArgs e, передаваемый в качестве параметра обработчику событий PaintEventHandler.

Using Fonts and Text

There are several classes offered by GDI+ and GDI for drawing text on Windows Forms. The GDI+ Graphics class has several DrawString methods that allow you to specify various features of text, such as location, bounding rectangle, font, and format. In addition, you can draw and measure text with GDI using the static DrawText and MeasureText methods offered by the TextRenderer class. The GDI methods also allow you to specify location, font, and format. You can choose either GDI or GDI+ for text rendering; however, GDI generally offers better performance and more accurate text measuring. Other classes that contribute to text rendering include FontFamily, Font, StringFormat, and TextFormatFlags.

How to: Construct Font Families and Fonts

GDI+ groups fonts with the same typeface but different styles into font families. For example, the Arial font family contains the following fonts:

GDI+ uses four styles to form families: regular, bold, italic, and bold italic. Adjectives such as narrow and rounded are not considered styles; rather they are part of the family name. For example, Arial Narrow is a font family with the following members:

Before you can draw text with GDI+, you need to construct a FontFamily object and a Font object. The FontFamily object specifies the typeface (for example, Arial), and the Font object specifies the size, style, and units.