Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 18-15 extracted from chapter Windows forms applications


Listing 18-14<     > Listing 18-16


This listing can be compiled with the command line:
csc.exe /target:exe Example_18_15.cs
Errors: 0 Warnings: 0


Example_18_15.cs
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D; 
public partial class AnimForm : Form {
   private float angle;
   private Timer timer = new Timer();
   public AnimForm() {
      timer.Enabled = true;
      timer.Tick += OnTimer;
      timer.Interval = 20;
      timer.Start();
      SetStyle( 
         ControlStyles.AllPaintingInWmPaint | 
         ControlStyles.UserPaint | 
         ControlStyles.OptimizedDoubleBuffer, true );
   }
   private void OnTimer( object sender, System.EventArgs e ) {
      angle ++;
      if (angle > 359)
         angle = 0;
      Refresh();
   }
   protected override void OnPaint( PaintEventArgs e ) {
      Graphics g = e.Graphics; 
      Matrix matrix = new Matrix();
      matrix.Rotate( angle, MatrixOrder.Append );
      matrix.Translate( this.ClientSize.Width / 2, 
                        this.ClientSize.Height/ 2MatrixOrder.Append);
      g.Transform = matrix;
      g.FillRectangle( Brushes.Azure, -100, -100200200 ); 
   }
   [System.STAThread]
   public static void Main() {
      Application.Run( new AnimForm() );
   }
}	
Copyright Patrick Smacchia 2006 2007