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-16 extracted from chapter Windows forms applications
Listing 18-15< > Listing 19-1
This listing can be compiled with the command line: csc.exe /target:exe Example_18_16.cs Errors: 0 Warnings: 0
Example_18_16.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();
private BufferedGraphics bufferedGraphics;
public AnimForm() {
BufferedGraphicsContext context = BufferedGraphicsManager.Current;
context.MaximumBuffer = new Size( this.Width + 1, this.Height + 1 );
bufferedGraphics = context.Allocate( this.CreateGraphics(),
new Rectangle( 0, 0, this.Width, this.Height) );
timer.Enabled = true;
timer.Tick += OnTimer;
timer.Interval = 20; // 50 images per second.
timer.Start();
}
private void OnTimer( object sender, System.EventArgs e ) {
angle ++;
if (angle > 359)
angle = 0;
Graphics g = bufferedGraphics.Graphics;
g.Clear( Color.Black );
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 );
bufferedGraphics.Render( Graphics.FromHwnd( this.Handle ) );
}
[System.STAThread]
public static void Main() {
Application.Run( new AnimForm() );
}
}
Copyright Patrick Smacchia 2006 2007
|