Restore the saved transformation : TranslateTransform « 2D Graphics « VB.Net Tutorial






Restore the saved transformation
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class RestoreSavedTransform
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

public class Form1
  Inherits System.Windows.Forms.Form

  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      e.Graphics.ScaleTransform(90, 90, MatrixOrder.Append)

      e.Graphics.TranslateTransform( _
          Me.ClientRectangle.Width \ 2, _
          Me.ClientRectangle.Height \ 2, _
          MatrixOrder.Append)

      Dim trans As Matrix = e.Graphics.Transform

      For i As Integer = 5 To 90 Step 5
          e.Graphics.Transform = trans

          e.Graphics.RotateTransform(i, MatrixOrder.Prepend)

          e.Graphics.DrawRectangle(New Pen(Color.Black, 0), -1, -1, 2, 2)
      Next i

  End Sub

  Public Sub New()
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  End Sub
End Class








17.79.TranslateTransform
17.79.1.Local transformationLocal transformation
17.79.2.Global transformationGlobal transformation
17.79.3.Transform and restoreTransform and restore
17.79.4.Restore the saved transformationRestore the saved transformation