Graphics.ResetTransform 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將這個 Graphics 的世界轉換矩陣重設為識別矩陣。
public:
void ResetTransform();
C#
public void ResetTransform();
member this.ResetTransform : unit -> unit
Public Sub ResetTransform ()
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
將 Windows Form 的世界轉換轉譯為向量 (100, 0)。
儲存表單的圖形狀態。
將表單的世界轉換重設為身分識別,並以純紅色筆刷填滿矩形。
還原翻譯的圖形狀態,並以純藍色筆刷填滿矩形。
結果是未轉譯的紅色填滿矩形和已轉譯的藍色填滿矩形。
public:
void SaveRestore1( PaintEventArgs^ e )
{
// Translate transformation matrix.
e->Graphics->TranslateTransform( 100, 0 );
// Save translated graphics state.
GraphicsState^ transState = e->Graphics->Save();
// Reset transformation matrix to identity and fill rectangle.
e->Graphics->ResetTransform();
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Red ), 0, 0, 100, 100 );
// Restore graphics state to translated state and fill second
// rectangle.
e->Graphics->Restore( transState );
e->Graphics->FillRectangle( gcnew SolidBrush( Color::Blue ), 0, 0, 100, 100 );
}
C#
private void SaveRestore1(PaintEventArgs e)
{
// Translate transformation matrix.
e.Graphics.TranslateTransform(100, 0);
// Save translated graphics state.
GraphicsState transState = e.Graphics.Save();
// Reset transformation matrix to identity and fill rectangle.
e.Graphics.ResetTransform();
e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 100, 100);
// Restore graphics state to translated state and fill second
// rectangle.
e.Graphics.Restore(transState);
e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 100);
}
Private Sub SaveRestore1(ByVal e As PaintEventArgs)
' Translate transformation matrix.
e.Graphics.TranslateTransform(100, 0)
' Save translated graphics state.
Dim transState As GraphicsState = e.Graphics.Save()
' Reset transformation matrix to identity and fill rectangle.
e.Graphics.ResetTransform()
e.Graphics.FillRectangle(New SolidBrush(Color.Red), 0, 0, 100, 100)
' Restore graphics state to translated state and fill second
' rectangle.
e.Graphics.Restore(transState)
e.Graphics.FillRectangle(New SolidBrush(Color.Blue), 0, 0, _
100, 100)
End Sub
識別矩陣代表沒有縮放、旋轉或轉譯的轉換。 將這個 Graphics 的世界轉換重設為識別矩陣,表示其世界轉換不會變更已轉換專案的幾何。
產品 | 版本 |
---|---|
.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 |