Mega Code Archive

 
Categories / C# / 2D Graphics
 

Transform and RotateTransform in a loop

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class Form1 : Form {     protected override void OnPaint(PaintEventArgs e) {     Graphics g = e.Graphics;     g.FillRectangle(Brushes.White, this.ClientRectangle);     Font f = new Font("Times New Roman", 16);     for (float angle = 0; angle < 360; angle += 45)     {       g.ResetTransform();       g.TranslateTransform(ClientRectangle.Width / 2,                  ClientRectangle.Height / 2);       g.RotateTransform(angle);       g.DrawString("Hello, World", f, Brushes.Black, 50, 0);     }     }     public static void Main() {         Application.Run(new Form1());     } }