August 2003
Intermediate to advanced
736 pages
14h 48m
English
Of course, deciding on a font is only half the fun. The real action is drawing strings after the font's been picked. For that, you use the DrawString method of the Graphics object:
using( Font font = new Font("Arial", 12) ) {
// This will wrap at new line characters
g.DrawString("line 1\nline 2", font, Brushes.Black, 10, 10);
}
The DrawString method takes, at a minimum, a string, a font, a brush to fill in the font characters, and a point. DrawString starts the drawing at the point and keeps going until it hits the edges of the region in the Graphics object. This includes translating new line characters as appropriate but does not include wrapping at word boundaries. To get the wrapping, you specify a layout rectangle:
using( Font ...
Read now
Unlock full access