Translate Transform three times : Transform « 2D Graphics « C# / C Sharp






Translate Transform three times

Translate Transform three times

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

public class Form1 : Form
{
      public Form1() {
            InitializeComponent();
      }
    private void SimpleStyleRenderer_Paint(object sender, PaintEventArgs e)
    {
      e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
      DrawRectangle(e.Graphics);
      e.Graphics.TranslateTransform(180, 60);
      DrawRectangle(e.Graphics);
      e.Graphics.TranslateTransform(-50, 80);
      DrawRectangle(e.Graphics);
      e.Graphics.TranslateTransform(-100, 50);
      DrawRectangle(e.Graphics);
    }

    private void DrawRectangle(Graphics g)
    {
      Pen drawingPen = new Pen(Color.Red, 30);
      g.DrawRectangle(drawingPen, new Rectangle(20, 20, 20, 20));
    }
    private void InitializeComponent()
    {
      this.SuspendLayout();

      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(600, 600);
      this.Name = "SimpleStyleRenderer";
      this.Text = "SimpleStyleRenderer";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.SimpleStyleRenderer_Paint);
      this.ResumeLayout(false);

    }
      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }
}


           
       








Related examples in the same category

1.Translate the text 150 pixels horizontally and 75 verticallyTranslate the text 150 pixels horizontally and 75 vertically
2.Add a translation to the existing transformationAdd a translation to the existing transformation
3.Reset the transformationReset the transformation
4.Shape and TransformShape and Transform
5.Translate TransformTranslate Transform
6.Rotate TransformRotate Transform