Lue englanniksi Muokkaa

Jaa


Region.Translate Method

Definition

Offsets the coordinates of this Region by the specified amount.

Overloads

Translate(Int32, Int32)

Offsets the coordinates of this Region by the specified amount.

Translate(Single, Single)

Offsets the coordinates of this Region by the specified amount.

Translate(Int32, Int32)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

Offsets the coordinates of this Region by the specified amount.

C#
public void Translate(int dx, int dy);

Parameters

dx
Int32

The amount to offset this Region horizontally.

dy
Int32

The amount to offset this Region vertically.

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, 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.

C#
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);
}

Applies to

.NET 10 (package-provided) ja muut versiot
Tuote Versiot
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Translate(Single, Single)

Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs
Source:
Region.cs

Offsets the coordinates of this Region by the specified amount.

C#
public void Translate(float dx, float dy);

Parameters

dx
Single

The amount to offset this Region horizontally.

dy
Single

The amount to offset this Region vertically.

Examples

For a code example, see the Translate(Single, Single) method.

Applies to

.NET 10 (package-provided) ja muut versiot
Tuote Versiot
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10