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 :

ProgressBar timer + mise à jour [Débutant]


Sujet :

C#

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut ProgressBar timer + mise à jour
    Bonjour à tous,

    J'ai décidé de me lancé dans la programmation en WPF pour voir ce que c'était et j'ai donc voulu faire un programme test. Actuellement je suis bloqué,
    J'aurais aimé crée une progress bar qui "avance" en fonction du temps.

    Donc de 0% à 100% en par exemple 10 secondes ( 10 000 millisecondes).
    Et j'aurais voulu qu'en même temps, la valeur de la progression soit affichée, donc par exemple si j'en suis à 43% que cela puisse s'afficher.

    On m'a dit d'utilisé un DispatcherTimer, j'ai aussi regardé des "tutoriels" sur Youtube, internet, j'ai fais des recherches mais je bloque, je n'arrive pas à trouver comment faire.


    C'est surement que mes connaissances sont faibles mais j'aurais aimé savoir et comprendre comment le faire.




    Voilà pourquoi je fais appel à vous, serait-il possible de m'expliquer comment faire, si possible de A à Z.



    J'aimerais faire ma progress Bar ici


    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
    private void button2_Click(object sender, RoutedEventArgs e)
            {
                if (ndc.Text.Length == 0 || mdp.Password.Length == 0)
                {
                    label4.Content = "Vous n'avez pas rempli tout les champs";
                    progressBar1.Value = 0;           
                }
                else
                {
     
     
                 {
     
                       /*"J'AIMERAIS METTRE ICI MA PROGRESS BAR AVEC LE TIMER" */
     
                    label4.Content = "Connexion en cours... " + progressBar1.Value + " %";                       
     
                    }
     
     
                        label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                    }
     
                }

    Merci

  2. #2
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    voila un exemple

    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
     
      public partial class MainWindow : Window
        {
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
     
            public MainWindow()
            {
                InitializeComponent();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = new TimeSpan(10000);
            }
            int i = 0;
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                i++;
                if (i <= 100)
                {
     
                    progressBar1.Value = i;
                    timer.Start();
                }
            }
     
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                timer.Start();
            }
        }

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Text.RegularExpressions;
    using System.Windows.Shapes;
    using System.Windows.Forms;
    using System.Windows.Threading;
    using System.Net;
    using System.Windows.Resources;
    using System.IO;
    using System.Threading;
    using Microsoft.Win32;
     
     
    namespace WpfApplication1
    {
        /// <summary>
        /// Logique d'interaction pour MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
     
            public MainWindow()
            {
                InitializeComponent();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = new TimeSpan(10000);
     
            }
     
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if ((mdp.Password.Length < 6) || (ndc.Text.Length < 4) || (email.Text.Length == 0))
                {
                    if (email.Text.Length == 0)
                    {
                        label4.Content = " Veuillez entrer un email";
                        email.Focus();
                    }
                    if (mdp.Password.Length < 6)
                    {
                        label4.Content = " Votre mot de passe doit faire 6 caractères au minimum";
                        mdp.Focus();
                    }
                    if (ndc.Text.Length < 4)
                    {
                        label4.Content = " Votre Nom de Compte doit faire au moins 4 caractères !";
                        ndc.Focus();
                    }
                }
                else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                {
                    label4.Content = "Veuillez entrer un email valide";
                    email.Select(0, email.Text.Length);
                    email.Focus();
                }
                else
                {
                    label4.Content = " Votre compte " + ndc.Text + " a bien été crée. Vous pouvez à présent vous connecter.";
     
                }
            }
     
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                if (ndc.Text.Length == 0 || mdp.Password.Length == 0)
                {
                    label4.Content = "Vous n'avez pas rempli tout les champs";
                    progressBar1.Value = 0;
                }
                else
                {
     
     
                    {
     
                              /* JE VOUDRAIS METTRE MON TIMER ICI SI POSSIBLE */
                       timer.Start();
     
                        label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                    }
     
     
                    label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                }
     
            }
     
     
            private void reset_Click(object sender, RoutedEventArgs e)
            {
                ndc.Text = String.Empty;
                mdp.Password = String.Empty;
                email.Text = String.Empty;
                label4.Content = String.Empty;
                progressBar1.Value = 0;
            }
     
            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                ndc.Text = "***";
                mdp.Password = "***";
                email.Text = "***@gmail.com";
                progressBar1.Value = 100;
                label4.Content = "Vos paramètres ont bien été chargées !";
     
     
            }
            int i = 0;
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                i++;
                if (i <= 100)
                {
                    progressBar1.Value = i;
                    timer.Start();
                }
     
     
            }
        }
    }


    Tout d'abord, merci d'avoir pris la peine de me répondre



    Il me reste maintenant à faire quoi pour que le timer se lance au moment où je clique sur mon bouton de connexion ?

    Je souhaite qu'il se lance a un moment précis, ( a l'endroit où je l'ai indiquer sur le code au dessus).


    Donc ça, j'ai réussi à le faire, mais lorsque le timer charge, le message "Connexion en cours" + progressBar.Value lui reste à 0%.


    J'aurais aimé savoir si il était possible de le faire augmenté au cours du temps. Donc qu'il augmente en même temps que le progress Bar.



    Et autre chose, la progress Bar a l'air de ne pas faire 10 secondes pour se remplir mais même pas 2 secondes même quand je met l'interval a 100 000 ou 1000.


    Merci =)

  4. #4
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Text.RegularExpressions;
    using System.Windows.Shapes;
    using System.Windows.Forms;
    using System.Windows.Threading;
    using System.Net;
    using System.Windows.Resources;
    using System.IO;
    using System.Threading;
    using Microsoft.Win32;
     
     
    namespace WpfApplication1
    {
        /// <summary>
        /// Logique d'interaction pour MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
     
            public MainWindow()
            {
                InitializeComponent();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = new TimeSpan(10000);
     
            }
     
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if ((mdp.Password.Length < 6) || (ndc.Text.Length < 4) || (email.Text.Length == 0))
                {
                    if (email.Text.Length == 0)
                    {
                        label4.Content = " Veuillez entrer un email";
                        email.Focus();
                    }
                    if (mdp.Password.Length < 6)
                    {
                        label4.Content = " Votre mot de passe doit faire 6 caractères au minimum";
                        mdp.Focus();
                    }
                    if (ndc.Text.Length < 4)
                    {
                        label4.Content = " Votre Nom de Compte doit faire au moins 4 caractères !";
                        ndc.Focus();
                    }
                }
                else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                {
                    label4.Content = "Veuillez entrer un email valide";
                    email.Select(0, email.Text.Length);
                    email.Focus();
                }
                else
                {
                    label4.Content = " Votre compte " + ndc.Text + " a bien été crée. Vous pouvez à présent vous connecter.";
     
                }
            }
     
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                if (ndc.Text.Length == 0 || mdp.Password.Length == 0)
                {
                    label4.Content = "Vous n'avez pas rempli tout les champs";
                    progressBar1.Value = 0;
                }
                else
                {
     
     
                    {
     
                              /* JE VOUDRAIS METTRE MON TIMER ICI SI POSSIBLE */
                       timer.Start();
     
                        label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                    }
     
     
                    label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                }
     
            }
     
     
            private void reset_Click(object sender, RoutedEventArgs e)
            {
                ndc.Text = String.Empty;
                mdp.Password = String.Empty;
                email.Text = String.Empty;
                label4.Content = String.Empty;
                progressBar1.Value = 0;
            }
     
            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                ndc.Text = "***";
                mdp.Password = "***";
                email.Text = "***@gmail.com";
                progressBar1.Value = 100;
                label4.Content = "Vos paramètres ont bien été chargées !";
     
     
            }
            int i = 0;
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                i++;
                if (i <= 100)
                {
                    progressBar1.Value = i;
    				label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
                    timer.Start();
                }
     
     
            }
        }
    }

  5. #5
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Merci ! Merci mille fois, ça aller faire bientôt deux jours que je bloquer dessus !



    Une dernière chose, savez vous pourquoi, lorsque je reset mes valeurs puis que je reclique sur Connexion, pourquoi le timer ne réagit plus ?


    En gros si je presse le bouton une deuxième fois, cela ne réagit pas.

    Une solution ? Sinon pas grave




    EDIT: J'aurais aussi aimé inserer un message une fois la progressBar a 100%. Pourriez vous m'indiquer la démarche à suivre s'il vous plait ?

    Merci !

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    93
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 93
    Points : 169
    Points
    169
    Par défaut
    Salut,

    J'ai parcouru très rapidement ton code, mais a priori tu ne réinitialises jamais ta variable 'i'.

    Du coup, la première fois elle est bien à 0 et va s'incrémenter jusqu'à 101.
    Quand tu vas recliquer sur ton "button_2", tu relances le timer mais la condition i <= 100 ne sera pas remplie.

    Il te reste donc à initialiser 'i' quand tu cliques sur ton bouton

  7. #7
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Text.RegularExpressions;
    using System.Windows.Shapes;
    using System.Windows.Forms;
    using System.Windows.Threading;
    using System.Net;
    using System.Windows.Resources;
    using System.IO;
    using System.Threading;
    using Microsoft.Win32;
     
     
    namespace WpfApplication1
    {
        /// <summary>
        /// Logique d'interaction pour MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
     
            public MainWindow()
            {
                InitializeComponent();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = new TimeSpan(10000);
     
            }
     
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if ((mdp.Password.Length < 6) || (ndc.Text.Length < 4) || (email.Text.Length == 0))
                {
                    if (email.Text.Length == 0)
                    {
                        label4.Content = " Veuillez entrer un email";
                        email.Focus();
                    }
                    if (mdp.Password.Length < 6)
                    {
                        label4.Content = " Votre mot de passe doit faire 6 caractères au minimum";
                        mdp.Focus();
                    }
                    if (ndc.Text.Length < 4)
                    {
                        label4.Content = " Votre Nom de Compte doit faire au moins 4 caractères !";
                        ndc.Focus();
                    }
                }
                else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                {
                    label4.Content = "Veuillez entrer un email valide";
                    email.Select(0, email.Text.Length);
                    email.Focus();
                }
                else
                {
                    label4.Content = " Votre compte " + ndc.Text + " a bien été crée. Vous pouvez à présent vous connecter.";
     
                }
            }
     
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                 i=0;
                if (ndc.Text.Length == 0 || mdp.Password.Length == 0)
                {
                    label4.Content = "Vous n'avez pas rempli tout les champs";
                    progressBar1.Value = 0;
                }
                else
                {
     
     
                    {
     
                              /* JE VOUDRAIS METTRE MON TIMER ICI SI POSSIBLE */
                       timer.Start();
     
                        label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                    }
     
     
                    label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                }
     
            }
     
     
            private void reset_Click(object sender, RoutedEventArgs e)
            {
                ndc.Text = String.Empty;
                mdp.Password = String.Empty;
                email.Text = String.Empty;
                label4.Content = String.Empty;
                progressBar1.Value = 0;
            }
     
            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                ndc.Text = "***";
                mdp.Password = "***";
                email.Text = "***@gmail.com";
                progressBar1.Value = 100;
                label4.Content = "Vos paramètres ont bien été chargées !";
     
     
            }
            int i = 0;
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                i++;
                if (i <= 100)
                {
                    progressBar1.Value = i;
    				label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
                    timer.Start();
                }
     
     
            }
        }
    }

  8. #8
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Encore une fois, merci à vous deux. Un autre problème de résolu !



    Concernant l'insertion d'un message une fois que la progress Bar a atteint 100%, c'est possible ?

    Car lorsque je j'ai essayé, j'ai eu un message d'erreur comme quoi, il n'était pas possible de convertir des int en bool quelque chose comme ça.



    Merci !

  9. #9
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    tu peux me donner le code ?!!

  10. #10
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    C'est le même code qu'avant

  11. #11
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    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
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Text.RegularExpressions;
    using System.Windows.Shapes;
    using System.Windows.Forms;
    using System.Windows.Threading;
    using System.Net;
    using System.Windows.Resources;
    using System.IO;
    using System.Threading;
    using Microsoft.Win32;
     
     
    namespace WpfApplication1
    {
        /// <summary>
        /// Logique d'interaction pour MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
     
            public MainWindow()
            {
                InitializeComponent();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = new TimeSpan(10000);
     
            }
     
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if ((mdp.Password.Length < 6) || (ndc.Text.Length < 4) || (email.Text.Length == 0))
                {
                    if (email.Text.Length == 0)
                    {
                        label4.Content = " Veuillez entrer un email";
                        email.Focus();
                    }
                    if (mdp.Password.Length < 6)
                    {
                        label4.Content = " Votre mot de passe doit faire 6 caractères au minimum";
                        mdp.Focus();
                    }
                    if (ndc.Text.Length < 4)
                    {
                        label4.Content = " Votre Nom de Compte doit faire au moins 4 caractères !";
                        ndc.Focus();
                    }
                }
                else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
                {
                    label4.Content = "Veuillez entrer un email valide";
                    email.Select(0, email.Text.Length);
                    email.Focus();
                }
                else
                {
                    label4.Content = " Votre compte " + ndc.Text + " a bien été crée. Vous pouvez à présent vous connecter.";
     
                }
            }
     
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                 i=0;
                if (ndc.Text.Length == 0 || mdp.Password.Length == 0)
                {
                    label4.Content = "Vous n'avez pas rempli tout les champs";
                    progressBar1.Value = 0;
                }
                else
                {
     
     
                    {
     
                              /* JE VOUDRAIS METTRE MON TIMER ICI SI POSSIBLE */
                       timer.Start();
     
                        label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                    }
     
     
                    label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
     
                }
     
            }
     
     
            private void reset_Click(object sender, RoutedEventArgs e)
            {
                ndc.Text = String.Empty;
                mdp.Password = String.Empty;
                email.Text = String.Empty;
                label4.Content = String.Empty;
                progressBar1.Value = 0;
            }
     
            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                ndc.Text = "***";
                mdp.Password = "***";
                email.Text = "***@gmail.com";
                progressBar1.Value = 100;
                label4.Content = "Vos paramètres ont bien été chargées !";
     
     
            }
            int i = 0;
            void timer_Tick(object sender, EventArgs e)
            {
                timer.Stop();
                i++;
                if (i <= 100)
                {
                    progressBar1.Value = i;
     
    				label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
                    timer.Start();
    				return;
                }
               MessageBox.Show("FIN");
     
            }
        }
    }

  12. #12
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Là, par contre ça ne fonctionne pas.

    Ca crée 100 MessageBox ( une à chaque %) et donc spawn mon ordi^^


    Moi j'aurais plutôt aimé que ça affiche un message UNIQUEMENT une fois arrivé à 100% et pas avant si possible.

  13. #13
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut
    tu a raté quelque chose je ne trouve pas ou mon code peux donner ce que tu dis :

    une fois je depasse 100

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     if (i <= 100)
                {
                    progressBar1.Value = i;
     
    	         label4.Content = "Connexion en cours... " + progressBar1.Value + " %";
                    timer.Start();
    		return;//il sort ici 
                }
               //il affiche le message lorsque i est supérieur à  100
               MessageBox.Show("FIN");
    a tu copies /colles le code ou ta fait la modification toi même ??

  14. #14
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    J'avais en effet oublié le return.


    Encore une erreur de ma part, désolé^^


    Et un grand merci pour vous !

  15. #15
    Membre émérite
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Points : 2 424
    Points
    2 424
    Par défaut

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

Discussions similaires

  1. ProgressBar mise à jour depuis une autre classe
    Par poussinvert dans le forum Android
    Réponses: 23
    Dernier message: 23/05/2012, 19h20
  2. Mise à jour d'une view par timer
    Par Evil850 dans le forum Composants graphiques
    Réponses: 2
    Dernier message: 28/05/2011, 11h58
  3. Forcer la mise à jour d'un progressbar
    Par colorid dans le forum Langage
    Réponses: 5
    Dernier message: 27/11/2010, 13h47
  4. [VBA-EXcel] Timer pour mise jour automatique
    Par Dos dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 12/09/2006, 20h36
  5. Réponses: 2
    Dernier message: 12/02/2003, 15h26

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