Region.Translate 方法

定義

依指定的量位移這個 Region 座標。

多載

Translate(Int32, Int32)

依指定的量位移這個 Region 座標。

Translate(Single, Single)

依指定的量位移這個 Region 座標。

Translate(Int32, Int32)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

依指定的量位移這個 Region 座標。

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

參數

dx
Int32

水準位移此 Region 的數量。

dy
Int32

垂直位移此 Region 的數量。

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:

  • 建立矩形,並以藍色將它繪製到螢幕。

  • 從矩形建立區域。

  • 將翻譯套用至區域。

  • 以紅色填滿翻譯的區域,並以紅色將翻譯的區域繪製到畫面。

請注意,紅色矩形會從原始矩形向下和向右移,以藍色顯示。

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

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Translate(Single, Single)

來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs
來源:
Region.cs

依指定的量位移這個 Region 座標。

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

參數

dx
Single

水準位移此 Region 的數量。

dy
Single

垂直位移此 Region 的數量。

範例

如需程式代碼範例,請參閱 Translate(Single, Single) 方法。

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9