Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Animation d’image: Agrandir le Globe

Modifier,le,mode,de,composition,d'une,image
{filelink=16666}

using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
 
public class AnimerImages : Form {
  private int largeur = 10;
  private int heuteur = 10;
 
  Image image= Image.FromFile("half.png");
  private Button arreter = new Button();
  Thread thread;
 
  public AnimerImages()
  {
    Text = "Animer la Globe";
    arreter.Text = "Arrêter";
    arreter.Location = new Point(5, 5);
    arreter.Click += new EventHandler(Abort_Click);
    Controls.Add(arreter);
 
    SetStyle(ControlStyles.DoubleBuffer
           | ControlStyles.AllPaintingInWmPaint
           | ControlStyles.UserPaint, true);
 
    thread = new Thread(new ThreadStart(Run));
    thread.Start();
  }
  protected void Abort_Click(object sender, EventArgs e) {
    thread.Abort();
  }
 
  protected override void OnPaint( PaintEventArgs e )   {
     Graphics g = e.Graphics;
     g.DrawRectangle(Pens.Black, 8, 8, largeur+3, heuteur+3);
     g.DrawImage(image, 10, 10, largeur, heuteur);
     base.OnPaint(e);
  }
 
  public void Run() {
      int frequenceX=3, frequenceY=3;
      while (true)
      {
        for(int i = 0; i < 500; i++) {
          largeur += frequenceX;
          heuteur += frequenceY;
          Invalidate();
          Thread.Sleep(30);
        }
        frequenceX = -frequenceX; frequenceY = -frequenceY;
      }
  }
  public static void Main( )
  {
      Application.Run(new AnimerImages());
  }
}

No comments yet.

Leave a Comment