Region.Translate Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Offsets the coordinates of this Region by the specified amount.
public:
void Translate(int dx, int dy);
public void Translate (int dx, int dy);
member this.Translate : int * int -> unit
Public Sub Translate (dx As Integer, dy As Integer)
Parameters
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.
void TranslateExample( PaintEventArgs^ e )
{
// Create the first rectangle and draw it to the screen in blue.
Rectangle regionRect = Rectangle(100,50,100,100);
e->Graphics->DrawRectangle( Pens::Blue, regionRect );
// Create a region using the first rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::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 = gcnew SolidBrush( Color::Red );
e->Graphics->FillRegion( myBrush, myRegion );
}
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);
}
Public Sub TranslateExample(ByVal e As PaintEventArgs)
' Create the first rectangle and draw it to the screen in blue.
Dim regionRect As New Rectangle(100, 50, 100, 100)
e.Graphics.DrawRectangle(Pens.Blue, regionRect)
' Create a region using the first rectangle.
Dim myRegion As 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.
Dim myBrush As New SolidBrush(Color.Red)
e.Graphics.FillRegion(myBrush, myRegion)
End Sub
Applies to
Translate(Single, Single)
- Source:
- Region.cs
- Source:
- Region.cs
- Source:
- Region.cs
Offsets the coordinates of this Region by the specified amount.
public:
void Translate(float dx, float dy);
public void Translate (float dx, float dy);
member this.Translate : single * single -> unit
Public Sub Translate (dx As Single, dy As Single)
Parameters
Examples
For a code example, see the Translate(Single, Single) method.