Region.Translate Method (Int32, Int32)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Offsets the coordinates of this Region by the specified amount.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public void Translate(
	int dx,
	int dy
)

Parameters

dx
Type: System.Int32

The amount to offset this Region horizontally.

dy
Type: System.Int32

The amount to offset this Region vertically.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a rectangle and draws it to the screen in blue.

  • Creates a region from the rectangle.

  • Applies the translation to the region.

  • Fills the translated region with red and draws the translated region to the screen in red.

Notice that the red rectangle is shifted down and to the right from the original rectangle, shown in blue.

public void TranslateExample(PaintEventArgs e)
{

    // Create the first rectangle and draw it to the screen in blue.
    Rectangle regionRect = new Rectangle(100, 50, 100, 100);
    e.Graphics.DrawRectangle(Pens.Blue, regionRect);

    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);

    // Apply the translation to the region.
    myRegion.Translate(150, 100);

    // Fill the transformed region with red and draw it to the screen in red.
    SolidBrush myBrush = new SolidBrush(Color.Red);
    e.Graphics.FillRegion(myBrush, myRegion);
}

.NET Framework
Available since 1.1
Return to top
Show: