10.9. Text Transformation

In Chapter 5 we discussed how to use the ScaleTransform, RotateTransform, and TranslateTransform methods to transform text. We can also use a transformation matrix to transform text.

We create a Matrix object with the transformation properties and apply it to the surface using the Transform property of the Graphics object. Listing 10.21 creates a Matrix object and sets it as the Transform property. We then call DrawString, which draws the text on the form. To test this code, add the code to a form’s paint event handler.

Listing 10.21. Text transformation example
 Graphics g = e.Graphics; string str = "Colors, fonts, and text are common" + " elements of graphics programming." + "In this chapter, you learned " + " about ...

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.