Transform and restore : TranslateTransform « 2D Graphics « VB.Net Tutorial






Transform and restore
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class TransformAndRestore
   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(150, 150, MatrixOrder.Append)

      For i As Integer = 5 To 30 Step 5
          Dim graphics_state As GraphicsState = e.Graphics.Save()
          e.Graphics.RotateTransform(i, MatrixOrder.Prepend)
          e.Graphics.DrawRectangle(New Pen(Color.Black, 0), -1, -1, 2, 2)
          e.Graphics.Restore(graphics_state)
      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