5.4. Working with Text and Strings
As we discussed in Chapter 3, the DrawString method of the Graphics class can be used to draw text on a graphics surface. The DrawString method takes a string, font, brush, and starting point.
Listing 5.8 creates three different fonts and draws text on a form using the DrawString method. Each DrawString method uses a different color and font to draw the string.
Listing 5.8. Drawing text on a graphics surface
private void DrawText_Click(object sender, System.EventArgs e) { // Create a Graphics object Graphics g = this.CreateGraphics(); // Create font families FontFamily verdanaFamily = new FontFamily("Verdana"); FontFamily arialFamily = new FontFamily("Arial"); // Construct Font objects Font verdanaFont = new ... |
Get Graphics Programming with GDI+ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.