Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 2.87 KB

using-the-world-transformation.md

File metadata and controls

45 lines (32 loc) · 2.87 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Using the World Transformation
Learn how to use the world transformation property that belongs to the Graphics class with several provided code examples.
03/30/2017
csharp
vb
graphics [Windows Forms], world transformation
world transformation [Windows Forms], examples
1e717711-1361-448e-aa49-0f3ec43110c9

Using the World Transformation

The world transformation is a property of the xref:System.Drawing.Graphics class. The numbers that specify the world transformation are stored in a xref:System.Drawing.Drawing2D.Matrix object, which represents a 3×3 matrix. The xref:System.Drawing.Drawing2D.Matrix and xref:System.Drawing.Graphics classes have several methods for setting the numbers in the world transformation matrix.

Different Types of Transformations

In the following example, the code first creates a 50×50 rectangle and locates it at the origin (0, 0). The origin is at the upper-left corner of the client area.

[!code-csharpSystem.Drawing.MiscLegacyTopics#11] [!code-vbSystem.Drawing.MiscLegacyTopics#11]

The following code applies a scaling transformation that expands the rectangle by a factor of 1.75 in the x direction and shrinks the rectangle by a factor of 0.5 in the y direction:

[!code-csharpSystem.Drawing.MiscLegacyTopics#12] [!code-vbSystem.Drawing.MiscLegacyTopics#12]

The result is a rectangle that is longer in the x direction and shorter in the y direction than the original.

To rotate the rectangle instead of scaling it, use the following code:

[!code-csharpSystem.Drawing.MiscLegacyTopics#13] [!code-vbSystem.Drawing.MiscLegacyTopics#13]

To translate the rectangle, use the following code:

[!code-csharpSystem.Drawing.MiscLegacyTopics#14] [!code-vbSystem.Drawing.MiscLegacyTopics#14]

See also