Animate Demo : Animation « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » AnimationScreenshots 
Animate Demo
Animate Demo

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds

Publisher: Apress
ISBN: 159059035X
*/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Animate_c
{
    public class AnimateDemo : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button cmdGo;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        /// 

    Bitmap RotatingBlocks;
    Point DrawHere;
    Rectangle InvalidRect;
    bool InProcess = false;
    private System.Windows.Forms.Button cmdStop;

        private System.ComponentModel.Container components = null;

        public AnimateDemo()
        {
          InitializeComponent();
    
          RotatingBlocks = new Bitmap("blocks.gif");
          DrawHere = new Point(1010);
          InvalidRect = new Rectangle(DrawHere, RotatingBlocks.Size);
    
          this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
          this.SetStyle(ControlStyles.DoubleBuffer,true);
          cmdStop.Enabled = false;
       }

        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            RotatingBlocks.Dispose();
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
      this.cmdGo = new System.Windows.Forms.Button();
      this.cmdStop = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // cmdGo
      // 
      this.cmdGo.Location = new System.Drawing.Point(160120);
      this.cmdGo.Name = "cmdGo";
      this.cmdGo.Size = new System.Drawing.Size(6432);
      this.cmdGo.TabIndex = 0;
      this.cmdGo.Text = "Animate";
      this.cmdGo.Click += new System.EventHandler(this.cmdGo_Click);
      // 
      // cmdStop
      // 
      this.cmdStop.Location = new System.Drawing.Point(240120);
      this.cmdStop.Name = "cmdStop";
      this.cmdStop.Size = new System.Drawing.Size(5632);
      this.cmdStop.TabIndex = 1;
      this.cmdStop.Text = "Stop";
      this.cmdStop.Click += new System.EventHandler(this.cmdStop_Click);
      // 
      // AnimateDemo
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(312157);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.cmdStop,
                                                                  this.cmdGo});
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "AnimateDemo";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "AnimateDemo";
      this.Load += new System.EventHandler(this.AnimateDemo_Load);
      this.ResumeLayout(false);

    }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new AnimateDemo());
        }

    private void AnimateDemo_Load(object sender, System.EventArgs e)
    {
    }

    private void OnFrameChanged(object o, EventArgs e
    {
      //Force a call to the Paint event handler.
      this.Invalidate(InvalidRect);
    }

    protected override void OnPaint(PaintEventArgs e
    {
      if !InProcess )
        return;
      
      //Get the next block ready to display.
      ImageAnimator.UpdateFrames(RotatingBlocks);
      //Draw the next frame in the RotatingBlocks animation.
      e.Graphics.DrawImage(RotatingBlocks, DrawHere);
    }

    private void cmdGo_Click(object sender, System.EventArgs e)
    {
      if (!InProcess
      {
        if ImageAnimator.CanAnimate(RotatingBlocks) )
        {
          //Begin the animation only once.
          ImageAnimator.Animate(RotatingBlocks, 
                                new EventHandler(this.OnFrameChanged));
          InProcess = true;
          cmdGo.Enabled = false;
          cmdStop.Enabled = true;
        }
      }
    }

    private void cmdStop_Click(object sender, System.EventArgs e)
    {
      ImageAnimator.StopAnimate(RotatingBlocks, 
                                new EventHandler(this.OnFrameChanged));
      InProcess = false;
      cmdGo.Enabled = true;
      cmdStop.Enabled = false;
    }

  }
}



           
       
Animate-c.zip( 6 k)
Related examples in the same category
1.Object collisionObject collision
2.Button click action to move a ballButton click action to move a ball
3.Animates a circleAnimates a circle
4.Uses a thread to Animate a ballUses a thread to Animate a ball
5.Animates an imageAnimates an image
6.Animation and double bufferAnimation and double buffer
7.Timer based animationTimer based animation
8.No Flicker (Flicker Free) AnimationNo Flicker (Flicker Free) Animation
9.Animate ImageAnimate Image
10.Animate Image with ImageAnimator
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.