IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

PictureBox translation animée


Sujet :

C#

  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2006
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 35
    Points : 21
    Points
    21
    Par défaut PictureBox translation animée
    Salut,
    Je suis entrain de développer une application avec C# WinForms où je dois dans l'un des forms translater quelques pictureBox. Pour l'instant voilà le code que j'utilise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                Point p=new Point(850,50);
                pictureBoxN.Location = p;
    mais le déplacement est brusque. Donc y aurait-il moyen d'effectuer une simple translation animée d'une position à une autre?

    Merci pour toute aide

  2. #2
    Membre averti Avatar de _PascalC_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2008
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2008
    Messages : 220
    Points : 428
    Points
    428
    Par défaut
    As-tu regardé du côté de WPF ? En Winforms il n'y a rien "de base" pour faire des animations.

    Pascal

  3. #3
    Membre à l'essai
    Inscrit en
    Mai 2006
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 35
    Points : 21
    Points
    21
    Par défaut
    J'ai vu quelque part que je pouvais inclure dans un UserControl WPF une animation SilverLight. Donc j'ai créé dans mon projet WinForms un UserControl WPF là où j'ai collé le code XAML fournis dans l'exemple puis j'ai ajouter à mon Form1.cs un WPF ElementHost et avec le "Select Hosted Content" j'ai choisi le UserControl que j'avais créé mais quand j'exécute ça donne rien

    Serait-il possible d'intégrer du code SilverLight dans un WinForm par exemple?
    J'ai même essayer avec le "Thread.Sleep()". Il s'arrête par exemple 1sec puis il change la position de l'image et il recommence jusqu'à la position désirée mais, il affiche l'image dans la position initiale puis se met à charger le long des x secondes et affiche l'image à la position finale donc c'est vraiment pas ce qui est recherché

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut transition dans l'animation d'un controle picturebox
    bonjour MABMA
    As-tu pense au timer pour faire une animation au lieu de mousedown ,mouseup....?
    Voici un exemple code qui fait defiler horizontalement un picturebox (mais avec un peu de math elementaire tu pourrais faire une rotation ou une pirouette ).
    La transition "smooth"( sans "saccade") est regle par un parametre "speed" variable en combinaison un timer.Interval faible(10)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
     
    namespace PanoramaImageWinCSharp
    {
        public partial class Form1 : Form
        {
            //set the "speed" of displacement
            int SPEED  = 0;
            //set the x and y of the picturebox
            int x ;
            int y;
            public Form1()
            {
                InitializeComponent();
                this.PictureBox1.Image = global::PanoramaImageWinCSharp.Properties.Resources.Nenuphars;
                this.Timer1.Interval = 10;
                PictureBox1.Left=0;
                PictureBox1.Top = btnStartAnimation.Top+50;
            }
     
            private void btnStartAnimation_Click(object sender, EventArgs e)
            {
                this.Timer1.Start();
                //set the x and y of the picturebox
                x = PictureBox1.Left;
                y = PictureBox1.Top;
            }
     
            private void btnStopAnimation_Click(object sender, EventArgs e)
            {
                this.Timer1.Stop();
                //set the x and y of the picturebox
                x = PictureBox1.Left;
                y = PictureBox1.Top;
            }
     
            private void Timer1_Tick(object sender, EventArgs e)
            {
                 SPEED +=5;
            //check if the picturebox is going off the form on right or left
            if (PictureBox1.Location.X + PictureBox1.Width > this.Width || PictureBox1.Location.X < 0) 
            {
                SPEED = 0;
            }
     
            //set the picturebox's location
            PictureBox1.Location = new Point(x + SPEED, y);
            }
        }
    }
    bonne animation et bon code...........

  5. #5
    Membre à l'essai
    Inscrit en
    Mai 2006
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 35
    Points : 21
    Points
    21
    Par défaut
    Citation Envoyé par MABROUKI Voir le message
    bonjour MABMA
    As-tu pense au timer pour faire une animation au lieu de mousedown ,mouseup....?
    Voici un exemple code qui fait defiler horizontalement un picturebox (mais avec un peu de math elementaire tu pourrais faire une rotation ou une pirouette ).
    La transition "smooth"( sans "saccade") est regle par un parametre "speed" variable en combinaison un timer.Interval faible(10)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
     
    namespace PanoramaImageWinCSharp
    {
        public partial class Form1 : Form
        {
            //set the "speed" of displacement
            int SPEED  = 0;
            //set the x and y of the picturebox
            int x ;
            int y;
            public Form1()
            {
                InitializeComponent();
                this.PictureBox1.Image = global::PanoramaImageWinCSharp.Properties.Resources.Nenuphars;
                this.Timer1.Interval = 10;
                PictureBox1.Left=0;
                PictureBox1.Top = btnStartAnimation.Top+50;
            }
     
            private void btnStartAnimation_Click(object sender, EventArgs e)
            {
                this.Timer1.Start();
                //set the x and y of the picturebox
                x = PictureBox1.Left;
                y = PictureBox1.Top;
            }
     
            private void btnStopAnimation_Click(object sender, EventArgs e)
            {
                this.Timer1.Stop();
                //set the x and y of the picturebox
                x = PictureBox1.Left;
                y = PictureBox1.Top;
            }
     
            private void Timer1_Tick(object sender, EventArgs e)
            {
                 SPEED +=5;
            //check if the picturebox is going off the form on right or left
            if (PictureBox1.Location.X + PictureBox1.Width > this.Width || PictureBox1.Location.X < 0) 
            {
                SPEED = 0;
            }
     
            //set the picturebox's location
            PictureBox1.Location = new Point(x + SPEED, y);
            }
        }
    }
    bonne animation et bon code...........
    Merci pour la réponse mais le compilateur ne reconnait pas "Nenuphars" dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.PictureBox1.Image = global::PanoramaImageWinCSharp.Properties.Resources.Nenuphars;
    et moi non plus. alors c'est quoi?

  6. #6
    Membre averti Avatar de _PascalC_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2008
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2008
    Messages : 220
    Points : 428
    Points
    428
    Par défaut
    Tu peux le deviner en regardant par quoi est utilisé ce "Nenuphars"

    Pascal

  7. #7
    Membre à l'essai
    Inscrit en
    Mai 2006
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 35
    Points : 21
    Points
    21
    Par défaut
    Oui c'est vrai

    Mais avec tout le code qui se compile correctement, rien ne se passe quand je click sur btnStartAnimation et voila le projet en pièce jointe
    Fichiers attachés Fichiers attachés

  8. #8
    Membre averti Avatar de _PascalC_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2008
    Messages
    220
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2008
    Messages : 220
    Points : 428
    Points
    428
    Par défaut
    Je viens de regarder et j'ai vu que tu n'avais pas associé les méthodes "btnStartAnimation", "btnStopAnimation" et "Timer1_Tick" aux différents contrôles. Tu peux faire ça par exemple depuis la fenêtre de propriétés de chaque contrôle (clique sur le petit éclair jaune).

    Pascal

  9. #9
    Membre à l'essai
    Inscrit en
    Mai 2006
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 35
    Points : 21
    Points
    21
    Par défaut
    c'est vrai
    ça marche enfin
    Merci beaucoup !!!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. appliquer un gif animé à une picturebox
    Par thor76160 dans le forum C#
    Réponses: 5
    Dernier message: 01/04/2010, 19h24
  2. gif animé dans picturebox
    Par jfrag dans le forum VB.NET
    Réponses: 8
    Dernier message: 18/07/2008, 15h42
  3. Jouer un GIF animé dans un PictureBox avec GDI+
    Par ProgElecT dans le forum Vos contributions VB6
    Réponses: 0
    Dernier message: 30/06/2008, 18h22
  4. Animation d'une image, translation, rotation en javascript ?
    Par Ptit_Mouss dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 15/09/2006, 11h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo