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 :

Actualisation de l'heure (secondes) dans la fenêtre


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 88
    Par défaut Actualisation de l'heure (secondes) dans la fenêtre
    Bonjour,

    J'ai créé un programme C# chargé de lancer des Notepad (cela peut-être autre chose) suivant le bouton sur lequel on clique.

    Dans la form principale (et unique) en haut à droite j'ai fais afficher l'heure (au format hh:mm:ss), donc toute les secondes ça se met à jour.

    Mais quand on clique sur un bouton, l'affichage de l'heure se fige. Elle se ré-actualise quand on ferme l'application lancée.

    Comment faire pour que l'heure ne fige plus ?
    car ça donne l'impression que le programme est planté en attendant que l'application choisit en cliquant se lance et vienne masqué mon programme.

    J'ai mis le tick dans la form principale et je pense qu'il faudrait le mettre dans "Program.cs" mais je n'y arrive pas, et c'est peut-être pas comme ça non plus qu'il faut faire...

    Merci de votre aide.

    Voici mon code ici et après un copie d'écran de l'unique fenêtre de mon programme :

    Program.cs :
    ------------
    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
     
    using System;
    using System.Threading;
    using System.Windows.Forms;
     
    namespace Selecteur
    {
        static class Program
        {
            /// <summary>
            /// Point d'entrée principal de l'application.
            /// </summary>
            /// 
     
            private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
            {
                MessageBox.Show(e.Exception.Message);
            }
     
            [STAThread]
            static void Main()
            {
                Application.ThreadException += new ThreadExceptionEventHandler(Program.Application_ThreadException);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new VuePrincipale());
            }
        }
    }

    VuePrincipale.CS :
    ------------------
    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
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
     
     
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.IO;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Threading;
     
    namespace Selecteur
    {
        //public partial class VuePrincipale : Form
        public class VuePrincipale : Form
        {
            private List<Button> listeBoutons = new List<Button>();
     
            // Nom du processus (nom de l'image) dans le gestionnaire de tâches correspondant à Notepad.exe
            const string K_nomProcess = "Notepad";
     
            // Chemin du fichier Xml utiliser lors du lancement de Notepad.exe
            const string K_fichierAppliXml = @"C:\TEST\Toto.Xml";
            const string K_nomFichierXml = "Toto.Xml";
     
            // Répertoire de base des fichiers de configuration
            // pour la génération automatique des boutons
            const string K_dossierConfig = @"C:\ListeInstallations";
     
            // Variables pour les messages d'erreur
            private string message, caption;
     
            // Variables globales
            private int DimXEcran, DimYEcran;
            private Label labelTitreVersion;
            private Label labelLigne1;
            private Label labelLigne2;
            private Label LabelAttente;
            private Label labelHorlogeDate;
            private Label labelHorlogeHeure;
     
     
            /// <summary>
            /// Définition de la vue principale de sélecteur
            /// <summary>
            public VuePrincipale()
            {
                System.Windows.Forms.Timer Horloge = new System.Windows.Forms.Timer();
     
                // Initialisation de la fenêtre            
                DimXEcran = Screen.PrimaryScreen.Bounds.Width;
                DimYEcran = Screen.PrimaryScreen.Bounds.Height;
                this.myInitializeComponent();
     
                Horloge.Tick += (s, e) =>
                {
                    labelHorlogeDate.Text = DateTime.Now.ToShortDateString();
                    labelHorlogeHeure.Text = DateTime.Now.ToLongTimeString();
                };
                Horloge.Interval = 500;
                Horloge.Start();
            }
     
     
            /// <summary>
            /// Initialisation de la fenêtre
            /// </summary>
            private void myInitializeComponent()
            {
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VuePrincipale));
     
                this.LabelAttente = new System.Windows.Forms.Label();
                this.labelTitreVersion = new System.Windows.Forms.Label();
                this.labelLigne1 = new System.Windows.Forms.Label();
                this.labelLigne2 = new System.Windows.Forms.Label();
                this.labelHorlogeDate = new System.Windows.Forms.Label();
                this.labelHorlogeHeure = new System.Windows.Forms.Label();
     
                // Supension de l'affichage jusqu'à la création de tous les contrôles et boutons
                this.SuspendLayout();
     
                // Ajout des boutons
                this.LectureFichiersConfBouton();
     
                // 
                // labelTitreVersion
                // 
                this.labelTitreVersion.BackColor = System.Drawing.Color.RoyalBlue;
                this.labelTitreVersion.ForeColor = System.Drawing.Color.White;
                this.labelTitreVersion.Font = new System.Drawing.Font("Calibri", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.labelTitreVersion.Location = new System.Drawing.Point(200, 0);
                this.labelTitreVersion.Name = "labelTitreVersion";
                this.labelTitreVersion.Size = new System.Drawing.Size(1280, 80);
                this.labelTitreVersion.TabIndex = 3;
                this.labelTitreVersion.Text = "SELECTEUR  DE  XML  ";
                this.labelTitreVersion.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                this.labelTitreVersion.Enabled = true;
     
                // 
                // labelLigne1
                // 
                this.labelLigne1.BackColor = System.Drawing.Color.White;
                this.labelLigne1.Font = new System.Drawing.Font("Arial", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.labelLigne1.Location = new System.Drawing.Point(0, 81);
                this.labelLigne1.Name = "labelLigne1";
                this.labelLigne1.Size = new System.Drawing.Size(838, 50);
                this.labelLigne1.TabIndex = 4;
                this.labelLigne1.Text = "Ligne 102";
                this.labelLigne1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     
                // 
                // labelLigne2
                // 
                this.labelLigne2.BackColor = System.Drawing.Color.White;
                this.labelLigne2.Font = new System.Drawing.Font("Arial", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.labelLigne2.Location = new System.Drawing.Point(841, 81);
                this.labelLigne2.Name = "labelLigne2";
                this.labelLigne2.Size = new System.Drawing.Size(838, 50);
                this.labelLigne2.TabIndex = 4;
                this.labelLigne2.Text = "Ligne 125";
                this.labelLigne2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     
                // 
                // LabelAttente
                // 
                this.LabelAttente.AutoSize = true;
                this.LabelAttente.Enabled = true;
                this.LabelAttente.Font = new System.Drawing.Font("Arial", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.LabelAttente.BackColor = System.Drawing.Color.Red;
                this.LabelAttente.ForeColor = System.Drawing.Color.White;
                this.LabelAttente.Location = new System.Drawing.Point((1680 / 2) - 170, (1050 / 2) - 31);
                this.LabelAttente.Name = "LabelAttente";
                this.LabelAttente.TabIndex = 1;
                this.LabelAttente.Text = "Veuillez patienter...";
                this.LabelAttente.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                this.LabelAttente.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                this.LabelAttente.Visible = false;
     
                // 
                // labelHorlogeDate
                // 
                this.labelHorlogeDate.BackColor = System.Drawing.Color.RoyalBlue;
                this.labelHorlogeDate.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.labelHorlogeDate.ForeColor = System.Drawing.Color.White;
                this.labelHorlogeDate.Location = new System.Drawing.Point(0, 0);
                this.labelHorlogeDate.Name = "labelHorlogeDate";
                this.labelHorlogeDate.Size = new System.Drawing.Size(200, 80);
                this.labelHorlogeDate.TabIndex = 5;
                this.labelHorlogeDate.Text = "";
                this.labelHorlogeDate.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     
                // 
                // labelHorlogeHeure
                // 
                this.labelHorlogeHeure.BackColor = System.Drawing.Color.RoyalBlue;
                this.labelHorlogeHeure.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.labelHorlogeHeure.ForeColor = System.Drawing.Color.White;
                this.labelHorlogeHeure.Location = new System.Drawing.Point(1480, 0);
                this.labelHorlogeHeure.Name = "labelHorlogeDate";
                this.labelHorlogeHeure.Size = new System.Drawing.Size(200, 80);
                this.labelHorlogeHeure.TabIndex = 5;
                this.labelHorlogeHeure.Text = "";
                this.labelHorlogeHeure.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     
                // 
                // VuePrincipale
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(DimXEcran * 2, DimYEcran);
                this.BackgroundImage = global::Selecteur.Properties.Resources.FondPlan_3360x1050;
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.Name = "VuePrincipale";
                this.Text = "Sélecteur";
     
                this.Controls.Add(this.LabelAttente);
                this.Controls.Add(this.labelTitreVersion);
                this.Controls.Add(this.labelLigne1);
                this.Controls.Add(this.labelLigne2);
                this.Controls.Add(this.labelHorlogeDate);
                this.Controls.Add(this.labelHorlogeHeure);
     
                this.ResumeLayout(false);
                this.PerformLayout();
            }
     
     
            /// <summary>
            /// Méthode qui génère un bouton
            /// </summary>
            private void GenererBouton(string nomBouton, int PosX, int PosY, int Larg, int Haut, bool Visibilite, string CheminAppIni)
            {
                // Instanciation du bouton
                Button bouton = new System.Windows.Forms.Button
                {
                    // Paramètres fixes du bouton
                    Size = new System.Drawing.Size(Larg, Haut),
                    Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))),
                    Location = new System.Drawing.Point(PosX, PosY),
                    FlatStyle = System.Windows.Forms.FlatStyle.Standard,
     
                    // Paramètres propres à chaque bouton
                    Name = nomBouton,
                    Text = nomBouton,
     
                    // Visibilité
                    Visible = Visibilite,
     
                    // Curseur souris
                    Cursor = Cursors.Hand,
     
                    // Version correspondant au bouton choisit
                    Tag = CheminAppIni
                };
     
                // Fonction du bouton sur son event Click
                bouton.Click += OnBoutonClicker;
     
                // Ajoute le bouton sur la fenêtre (VuePrincipale)
                listeBoutons.Add(bouton);
                this.Controls.Add(bouton); // 'this' fait référence à VuePrincipale
            }
     
     
            /// <summary>
            /// Méthode ferme proprement l'application
            /// </summary>
            private void FermerApplication()
            {
                this.Dispose();
                this.Close();
                Application.ExitThread();
                Application.Exit();
            }
     
     
            /// <summary>
            /// Méthode appelée lorsqu'on clique sur un bouton
            /// </summary>
            private void OnBoutonClicker(object sender, EventArgs e)
            {
                string cheminDossierXml, cheminAppliGen;
                FileInfo[] fichiers;
     
                // Récupération du bouton sollicité
                Button bouton = (Button)sender;
     
                // Chemin de l'application correspondant au bouton choisit
                cheminAppliGen = bouton.Tag.ToString(); //bouton.Tag.ToString().Split(new char[] { ';' })[1];
     
                // cheminAppli = répertoire contenant les fichiers bat utilisés pour lancer les aplis
                string cheminAppli = cheminAppliGen + @"\NotepadLauncher\Poste PMS\";
                DirectoryInfo Dossier = new DirectoryInfo(cheminAppli);
                try
                {
                    fichiers = Dossier.GetFiles("*RIM_?.bat", SearchOption.TopDirectoryOnly);
                }
                catch (Exception exception)
                {
                    message = exception.Message;
                    caption = "Erreur";
                    MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
     
                // Si il n'y a pas e .bat à lancer
                if ((Dossier.GetFiles("*not_?.bat", SearchOption.TopDirectoryOnly).Length) < 1)
                {
                    message = "Le dossier \"" + cheminAppli + "\" ne contient aucun fichier à lancer (*not_*.bat).\n\r";
                    caption = "Erreur";
                    MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
     
                // Modification des boutons
                AffichageMessage(true, bouton.Name);
                ActiveBouton(false);
                bouton.BackColor = Color.RoyalBlue;
                bouton.ForeColor = Color.White;
                bouton.Enabled = true;
     
                // Test si des processus Notepad sont en cours d'exécution et les ferment si c'est le cas
                Process[] mesProcess = Process.GetProcessesByName(K_nomProcess);
                foreach (Process p in mesProcess)
                {
                    p.Kill(); // Tuer tout les processus recupérés
                }
     
                // Lancer les .bat correspondants au bouton sollicité
                int i = 0;
                ProcessStartInfo[] prog = new ProcessStartInfo[fichiers.Length];
                Process[] mesProcessBat = new Process[fichiers.Length];
     
                // On boucle s'il y a plusieurs .bat à lancer
                foreach (FileInfo file in fichiers)
                {
                    prog[i] = new ProcessStartInfo(cheminAppli + file.ToString())
                    {
                        // Initialise la fenêtre et redirige la sortie
                        CreateNoWindow = true,
                        UseShellExecute = false
                    };
     
                    // Déclaration d'un nouveau processus : permet de faire un mesProcess.WaitForExit() si besoin et démarrage de l'application Notepad.exe
                    mesProcessBat[i] = Process.Start(prog[i]);
                    Thread.Sleep(100); // Attente de 100ms
                    mesProcessBat[i].WaitForExit();
     
                    i += 1;
                }
     
                // Vérification des processus Notepad
                // Boucle tant que tous les Notepad ne sont pas lancés
                while (Process.GetProcessesByName(K_nomProcess).Count() < i) ;
                Process[] mesProcessNotepad = Process.GetProcessesByName(K_nomProcess);
                foreach (Process processNotepad in mesProcessNotepad)
                {
                    processNotepad.WaitForExit();
                }
     
                // Vérifie les processus Notepad en fonctionnement
                if (!CheckRunningProcess(mesProcessNotepad))
                {
                    AffichageMessage(false, bouton.Name);
                    ActiveBouton(true);
                }
     
            }
     
     
            /// <summary>
            /// Fonction qui renvoie vrai si des processus Notepad sont en cours, faux sinon.
            /// </summary>
            private bool CheckRunningProcess(Process[] mesProcess)
            {
                bool isRunning = false;
                foreach (Process process in mesProcess)
                {
                    if (!process.HasExited)
                    {
                        isRunning = true;
                    }
                    else
                    {
                        process.Close();
                        process.Dispose();
                    }
                }
                return isRunning;
            }
     
     
            /// <summary>
            /// Méthode qui fait apparaitre le message d'attente ou la sortie
            /// </summary>
            private void AffichageMessage(bool flagMessage, string nomBouton)
            {
                LabelAttente.Text = "Lancement du Notepad\n\rde " + nomBouton + " en cours.\n\rVeuillez patienter...";
                LabelAttente.Visible = flagMessage;
     
                if (!flagMessage)
                {
                    MessageBox.Show("L'application du Notepad\n\rde " + nomBouton + " a été fermée.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
     
     
            /// <summary>
            /// Méthode qui initialise les boutons
            /// </summary>
            private void ActiveBouton(bool flagActive)
            {
                //Initialise les boutons
                foreach (Button b in listeBoutons)
                {
                    b.Enabled = flagActive;
                    b.BackColor = System.Drawing.SystemColors.Control;
                    b.ForeColor = System.Drawing.SystemColors.ControlText;
                    b.UseVisualStyleBackColor = true;
                }
                if (!flagActive) this.Cursor = Cursors.WaitCursor; else this.Cursor = Cursors.Default;
            }
     
     
            /// <summary>
            /// Méthode qui lit les fichiers de configurations des boutons
            /// </summary>
            private void LectureFichiersConfBouton()
            {
                string nomBouton = "", CheminAppIni= "", line;
                string[] strArray;
                int PosX = 0, PosY = 0, Larg = 0, Haut = 0;
                bool Visibilite = false;
     
                if (!Directory.Exists(K_dossierConfig))
                {
                    message = "Erreur le dossier \"" + K_dossierConfig + "\" n'existe pas.\n\r";
                    message += "\n\rL'application va se fermer.";
                    caption = "Erreur";
                    MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    FermerApplication();
                    return;
                }
     
                DirectoryInfo Dossier = new DirectoryInfo(K_dossierConfig);
                FileInfo[] fichiers = Dossier.GetFiles("*.ini", SearchOption.AllDirectories);
                int nbFichiersIni = Dossier.GetFiles("*.ini", SearchOption.AllDirectories).Length - 1;
     
                if (nbFichiersIni < 1)
                {
                    message = "Il n'y a aucun fichier de configuration (*.ini) dans le dossier \"" + K_dossierConfig + "\" ou ces sous-dossiers.\n\r";
                    message += "\n\rL'application va se fermer.";
                    caption = "Erreur";
                    MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    FermerApplication();
                    return;
                }
     
                foreach (FileInfo fichier in fichiers)
                {
                    try
                    {
                        using (StreamReader reader = new StreamReader(fichier.FullName))
                        {
     
                            while ((line = reader.ReadLine()) != null)
                            {
                                strArray = line.Split(new char[] { '=' });
     
                                switch (strArray[0])
                                {
                                    case "Nom":
                                        nomBouton = strArray[1];
                                        break;
     
                                    case "PosX":
                                        PosX = Convert.ToInt32(strArray[1]);
                                        break;
     
                                    case "PosY":
                                        PosY = Convert.ToInt32(strArray[1]);
                                        break;
     
                                    case "DimX":
                                        Larg = Convert.ToInt32(strArray[1]);
                                        break;
     
                                    case "DimY":
                                        Haut = Convert.ToInt32(strArray[1]);
                                        break;
     
                                    case "Visible":
                                        Visibilite = (strArray[1] == "True" || strArray[1] == "true");
                                        break;
     
                                    case "CheminAppIni":
                                        CheminAppIni = strArray[1];
                                        break;
                                }
                            }
     
                            GenererBouton(nomBouton, PosX, PosY, Larg, Haut, Visibilite, CheminAppIni);
                            reader.Close();
                            reader.Dispose();
                        }
                    }
                    catch (Exception exception)
                    {
                        message = exception.Message;
                        message += "\n\r\n\rL'application va se fermer.";
                        caption = "Erreur";
                        MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        FermerApplication();
                        return;
                    }
     
                }
            }
     
        }
    }

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Février 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Février 2009
    Messages : 155
    Par défaut
    Essaie voir comme ça :

    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
    static class Program
        {
            /// <summary>
            /// Point d'entrée principal de l'application.
            /// </summary>
            /// 
            public static System.Windows.Forms.Timer Horloge;
     
            private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
            {
                MessageBox.Show(e.Exception.Message);
            }
     
            [STAThread]
            static void Main()
            {
                Horloge = new System.Windows.Forms.Timer();
     
                Application.ThreadException += new ThreadExceptionEventHandler(Program.Application_ThreadException);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new VuePrincipale());
            }
        }
    }
    et dans la vue principale tu appelles Program.Horloge :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
                Program.Horloge.Tick += (s, e) =>
                {
                    labelHorlogeDate.Text = DateTime.Now.ToShortDateString();
                    labelHorlogeHeure.Text = DateTime.Now.ToLongTimeString();
                };
                Program.Horloge.Interval = 500;
                Program.Horloge.Start();
    On verra ce que ça donne une fois les boutons activés...

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    15
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 15
    Par défaut
    Bonjour,

    L'affichage ne s'actualise plus à cause de la méthode WaitForExit qui est bloquante. Je conseille d'utiliser l'événement Exited pour déterminer si l'un des processus est terminé.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 88
    Par défaut
    Bonjour,

    @KRANTZ :
    On verra ce que ça donne une fois les boutons activés...
    C'est pas grave, car une fois un bouton cliqué, le programme est masqué par l'application lancée (via le bouton).
    Je vais commencer par tester ça.


    @Dfgs : je verrais plus tard, et si besoin, car cela implique une petite refonte.


    Merci

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 88
    Par défaut
    @KRANTZ : ta solution ne fonctionne pas. (j'avais testé qq comme ça avant mais sans plus de résultats.)

Discussions similaires

  1. [WM22] Actualisation heure dans une fenêtre
    Par Invité dans le forum Windev Mobile
    Réponses: 9
    Dernier message: 31/01/2017, 16h22
  2. ajouter la date et l'heure actuel dans une fenêtre qui contient un tableau datafile
    Par med31075 dans le forum Interfaces Graphiques en Java
    Réponses: 13
    Dernier message: 09/03/2014, 13h10
  3. Réponses: 1
    Dernier message: 30/09/2008, 20h40
  4. heure avec centieme de seconde dans un etat
    Par petitours dans le forum Access
    Réponses: 17
    Dernier message: 28/01/2006, 21h05
  5. actualiser page après validation formulai dans autre fenêtre
    Par allowen dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 05/01/2006, 16h02

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