using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Media; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Bonhomme02 { public partial class Form1 : Form { private Bonhomme bonhomme; private Marcher marche; private BufferedGraphics bufferG = null; private Graphics g; SoundPlayer player = new SoundPlayer(); Stream str = global::Bonhomme02.Properties.Resources.NyanCatoriginal; List tasks = new List(); public Form1() { InitializeComponent(); // Modification contre le scintillement - Creation d'une mémoire tampon graphique bufferG = BufferedGraphicsManager.Current.Allocate(TV.CreateGraphics(), TV.DisplayRectangle); g = bufferG.Graphics; } private void timerImage_Tick(object sender, EventArgs e) { if (/*this.bonhomme.Origine.X + this.bonhomme.Lhorizontal >= this.TV.Width*/1==2) { this.timerImage.Stop(); this.btnStopDeplacerCTick.Enabled = false; } else { bonhomme.Cacher(this.TV.Handle); bonhomme.coordonnee = new Point(bonhomme.coordonnee.X + 3, bonhomme.coordonnee.Y + 0); bonhomme.jambe1.BougerBas(+3, -3); bonhomme.Afficher(this.TV.Handle); } } private void btnStopDeplacerCTick_Click(object sender, EventArgs e) { this.timerImage.Stop(); this.btnStopDeplacerCTick.Enabled = false; } private void btnEffacer_Click(object sender, EventArgs e) { Graphics gr = Graphics.FromHwnd(this.TV.Handle); gr.FillRectangle(new SolidBrush(this.TV.BackColor), 0, 0, this.TV.Bounds.Width, this.TV.Bounds.Height); } private void btnCreationCarrosse_Click(object sender, EventArgs e) { bonhomme = new Bonhomme(this.TV, 80, 80, 50, 20, Math.PI / 2); bonhomme.jambe1.Bas.Fond = bonhomme.jambe1.Millieux.Fond = bonhomme.jambe1.Haut.Fond = Color.Pink; bonhomme.jambe2.Bas.Fond = bonhomme.jambe2.Millieux.Fond = bonhomme.jambe2.Haut.Fond = Color.DeepPink; bonhomme.tete.Fond = Color.Pink; bonhomme.Afficher(this.TV.Handle); marche = new Marcher(ref bonhomme, this.TV.Handle, this.Sol.Location.Y-this.TV.Location.Y); Thread.Sleep(1000); if (tasks.Count == 0) { player.Stream = str; this.pictureBox2.Image = global::Bonhomme02.Properties.Resources.tumblr_opsismTLqh1vghf22o1_400; player.Play(); } // https://msdn.microsoft.com/fr-be/Library/dd270696(v=vs.110).aspx tasks.Add(Task.Factory.StartNew(() => { marche.Avancer(1, this.TV.Width); })); var continuation = Task.WhenAll(tasks); //https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks Task continuationTask = continuation.ContinueWith((antecedent) => { tasks.RemoveAt(0); if (tasks.Count == 0) { player.Stop(); this.pictureBox2.Image = null; } }); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_MouseMove(object sender, MouseEventArgs e) { MousePosition.Offset(this.Location); Console.WriteLine(MousePosition); } } }