Region.Translate 方法

定义

将此 Region 的坐标偏移指定的量。

重载

Translate(Int32, Int32)

将此 Region 的坐标偏移指定的量。

Translate(Single, Single)

将此 Region 的坐标偏移指定的量。

Translate(Int32, Int32)

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

将此 Region 的坐标偏移指定的量。

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)

参数

dx
Int32

Region 的水平偏移量。

dy
Int32

Region 的垂直偏移量。

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 创建一个矩形并将其绘制到蓝色屏幕。

  • 从矩形创建区域。

  • 将转换应用于区域。

  • 用红色填充已翻译的区域,并将翻译的区域绘制到红色屏幕。

请注意,红色矩形从原始矩形向下向右移动,以蓝色显示。

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

适用于

Translate(Single, Single)

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

将此 Region 的坐标偏移指定的量。

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)

参数

dx
Single

Region 的水平偏移量。

dy
Single

Region 的垂直偏移量。

示例

有关代码示例,请参阅 Translate(Single, Single) 方法。

适用于