/* * A C# program that demonstrates use of transforms * * Ben Bederson, April 2, 2002 */ using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; public class TransformDemo : System.Windows.Forms.Form { static public void Main() { Application.Run(new TransformDemo()); } public TransformDemo() { Size = new Size(400, 400); StartPosition = FormStartPosition.CenterScreen; TransformControl control = new TransformControl(); control.Location = new Point(0, 0); control.Size = new Size(400, 400); Controls.Add(control); } } class TransformControl : Control { static Brush redBrush = new SolidBrush(Color.Red); static Brush blueBrush = new SolidBrush(Color.Blue); static Brush orangeBrush = new SolidBrush(Color.Orange); public TransformControl() { BackColor = Color.White; } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Matrix m = new Matrix(); g.FillRectangle(redBrush, 0, 0, 20, 20); m.Translate(100, 0); g.Transform = m; g.FillRectangle(blueBrush, 0, 0, 20, 20); m.Rotate(30); g.Transform = m; g.FillRectangle(orangeBrush, 0, 0, 20, 20); } }