O'Reilly logo

Graphics Programming with GDI+ by Mahesh Chand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required