Region.Translate 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以指定的數量來位移這個 Region 的座標。
多載
Translate(Int32, Int32) |
以指定的數量來位移這個 Region 的座標。 |
Translate(Single, Single) |
以指定的數量來位移這個 Region 的座標。 |
Translate(Int32, Int32)
以指定的數量來位移這個 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)
參數
範例
下列程式碼範例是設計來搭配Windows Forms使用,而且需要 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)
以指定的數量來位移這個 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)
參數
範例
如需程式碼範例,請參閱 Translate(Single, Single) 方法。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將推出:在 2024 年,我們將隨著內容的意見反應機制逐步淘汰 GitHub 問題,並以新的意見反應系統來取代。 如需詳細資訊,請參閱提交並檢視相關的意見反應