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-14 extracted from chapter Windows forms applications
Listing 18-13< > Listing 18-15
This listing can be compiled with the command line: csc.exe /target:exe Example_18_14.cs Errors: 0 Warnings: 0
Example_18_14.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; // 20 milliseconds => 50 images per second.
timer.Start();
}
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/ 2, MatrixOrder.Append);
g.Transform = matrix;
g.FillRectangle( Brushes.Azure, -100, -100, 200, 200 );
}
[System.STAThread]
public static void Main() {
Application.Run( new AnimForm() );
}
}
Copyright Patrick Smacchia 2006 2007
|