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 :

Série de button, un seul fonctionne [Débutant]


Sujet :

C#

  1. #1
    Membre du Club
    Inscrit en
    Mai 2011
    Messages
    72
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 72
    Points : 49
    Points
    49
    Par défaut Série de button, un seul fonctionne
    Bonjour à tous,

    Je suis nouveau dans le C#
    J'essaie de faire un petit logiciel pour accelerer quelques procédures dans mon travail.

    J'ai une série de boutons, qui ouvre tel ou tel fichier txt.

    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
    using System;
    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.Diagnostics;
     
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void PREP_PGD_Click(object sender, EventArgs e)
            {
                var psi1 = new ProcessStartInfo();
                psi1.FileName = "notepad.exe";
                psi1.Arguments = @"C:\nam\PREP_PGD.nam";
                psi1.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi1;
                process.Start();
                process.WaitForExit();
            }
     
     
            private void PREP_NEST_PGD_Click(object sender, EventArgs e)
            {
                var psi2 = new ProcessStartInfo();
                psi2.FileName = "notepad.exe";
                psi2.Arguments = @"C:\nam\PREP_NEST_PGD.nam";
                psi2.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi2;
                process.Start();
                process.WaitForExit();
            }
     
            private void PREP_REAL_CASE_Click(object sender, EventArgs e)
            {
                var psi3 = new ProcessStartInfo();
                psi3.FileName = "notepad.exe";
                psi3.Arguments = @"C:\nam\PREP_REAL_CASE.nam";
                psi3.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi3;
                process.Start();
                process.WaitForExit();
            }
     
            private void SPAWNING_Click(object sender, EventArgs e)
            {
                var psi4 = new ProcessStartInfo();
                psi4.FileName = "notepad.exe";
                psi4.Arguments = @"C:\nam\SPAWN1.nam";
                psi4.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi4;
                process.Start();
                process.WaitForExit();
            }
     
            private void EXSEG1_Click(object sender, EventArgs e)
            {
                var psi5 = new ProcessStartInfo();
                psi5.FileName = "notepad.exe";
                psi5.Arguments = @"C:\nam\EXSEG1.nam";
                psi5.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi5;
                process.Start();
                process.WaitForExit();
            }
     
     
            private void EXSEG2_Click(object sender, EventArgs e)
            {
                var psi6 = new ProcessStartInfo();
                psi6.FileName = "notepad.exe";
                psi6.Arguments = @"C:\nam\EXSEG2.nam";
                psi6.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi6;
                process.Start();
                process.WaitForExit();
            }
    Mon problème étant que seul le dernier bouton (ici EXSEG2) m'ouvre bien mon fichier .nam. Lorsque je clique sur les autres, rien ne se passe.

    Quelqu'un aurait une idée ?

    Je vous remercie de votre aide

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2009
    Messages
    2 032
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2009
    Messages : 2 032
    Points : 5 476
    Points
    5 476
    Par défaut
    Euh, question bête :
    tout tes evenements clicks de chaque bouton sont bien "reliés" à une méthode?

    (Au pire mets nous la partie designer.cs)

  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 196
    Points : 197
    Points
    197
    Par défaut
    en fait je crois que ça vient du fait que tu ne ferme jamais ton process.
    Il faut faire process.ExitCode lorsque tu fermes notepad

  4. #4
    Membre du Club
    Inscrit en
    Mai 2011
    Messages
    72
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 72
    Points : 49
    Points
    49
    Par défaut
    designer.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
    namespace WindowsFormsApplication3
    {
        partial class Form1
        {
            /// <summary>
            /// Variable nécessaire au concepteur.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
     
            /// <summary>
            /// Nettoyage des ressources utilisées.
            /// </summary>
            /// <param name="disposing">true si les ressources managées doivent être supprimées*; sinon, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
     
            #region Code généré par le Concepteur Windows Form
     
            /// <summary>
            /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
            /// le contenu de cette méthode avec l'éditeur de code.
            /// </summary>
            private void InitializeComponent()
            {
                this.EXSEG1 = new System.Windows.Forms.Button();
                this.PREP_PGD = new System.Windows.Forms.Button();
                this.PREP_NEST_PGD = new System.Windows.Forms.Button();
                this.PREP_REAL_CASE = new System.Windows.Forms.Button();
                this.EXSEG2 = new System.Windows.Forms.Button();
                this.SPAWNING = new System.Windows.Forms.Button();
                this.groupBox1 = new System.Windows.Forms.GroupBox();
                this.groupBox1.SuspendLayout();
                this.SuspendLayout();
                // 
                // EXSEG1
                // 
                this.EXSEG1.Location = new System.Drawing.Point(19, 144);
                this.EXSEG1.Name = "EXSEG1";
                this.EXSEG1.Size = new System.Drawing.Size(75, 23);
                this.EXSEG1.TabIndex = 0;
                this.EXSEG1.Text = "EXSEG1";
                this.EXSEG1.UseVisualStyleBackColor = true;
                // 
                // PREP_PGD
                // 
                this.PREP_PGD.Location = new System.Drawing.Point(56, 28);
                this.PREP_PGD.Name = "PREP_PGD";
                this.PREP_PGD.Size = new System.Drawing.Size(75, 23);
                this.PREP_PGD.TabIndex = 1;
                this.PREP_PGD.Text = "PREP_PGD";
                this.PREP_PGD.UseVisualStyleBackColor = true;
                // 
                // PREP_NEST_PGD
                // 
                this.PREP_NEST_PGD.Location = new System.Drawing.Point(31, 57);
                this.PREP_NEST_PGD.Name = "PREP_NEST_PGD";
                this.PREP_NEST_PGD.Size = new System.Drawing.Size(125, 23);
                this.PREP_NEST_PGD.TabIndex = 2;
                this.PREP_NEST_PGD.Text = "PREP_NEST_PGD";
                this.PREP_NEST_PGD.UseVisualStyleBackColor = true;
                // 
                // PREP_REAL_CASE
                // 
                this.PREP_REAL_CASE.Location = new System.Drawing.Point(31, 86);
                this.PREP_REAL_CASE.Name = "PREP_REAL_CASE";
                this.PREP_REAL_CASE.Size = new System.Drawing.Size(125, 23);
                this.PREP_REAL_CASE.TabIndex = 3;
                this.PREP_REAL_CASE.Text = "PREP_REAL_CASE";
                this.PREP_REAL_CASE.UseVisualStyleBackColor = true;
                // 
                // EXSEG2
                // 
                this.EXSEG2.Location = new System.Drawing.Point(100, 144);
                this.EXSEG2.Name = "EXSEG2";
                this.EXSEG2.Size = new System.Drawing.Size(75, 23);
                this.EXSEG2.TabIndex = 4;
                this.EXSEG2.Text = "EXSEG2";
                this.EXSEG2.UseVisualStyleBackColor = true;
                this.EXSEG2.Click += new System.EventHandler(this.EXSEG2_Click);
                // 
                // SPAWNING
                // 
                this.SPAWNING.Location = new System.Drawing.Point(56, 115);
                this.SPAWNING.Name = "SPAWNING";
                this.SPAWNING.Size = new System.Drawing.Size(75, 23);
                this.SPAWNING.TabIndex = 5;
                this.SPAWNING.Text = "SPAWNING";
                this.SPAWNING.UseVisualStyleBackColor = true;
                // 
                // groupBox1
                // 
                this.groupBox1.Controls.Add(this.EXSEG2);
                this.groupBox1.Controls.Add(this.SPAWNING);
                this.groupBox1.Controls.Add(this.EXSEG1);
                this.groupBox1.Controls.Add(this.PREP_PGD);
                this.groupBox1.Controls.Add(this.PREP_REAL_CASE);
                this.groupBox1.Controls.Add(this.PREP_NEST_PGD);
                this.groupBox1.Location = new System.Drawing.Point(12, 11);
                this.groupBox1.Name = "groupBox1";
                this.groupBox1.Size = new System.Drawing.Size(194, 187);
                this.groupBox1.TabIndex = 6;
                this.groupBox1.TabStop = false;
                this.groupBox1.Text = "groupBox1";
                this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1373, 628);
                this.Controls.Add(this.groupBox1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.groupBox1.ResumeLayout(false);
                this.ResumeLayout(false);
     
            }
     
            #endregion
     
            private System.Windows.Forms.Button EXSEG1;
            private System.Windows.Forms.Button PREP_PGD;
            private System.Windows.Forms.Button PREP_NEST_PGD;
            private System.Windows.Forms.Button PREP_REAL_CASE;
            private System.Windows.Forms.Button EXSEG2;
            private System.Windows.Forms.Button SPAWNING;
            private System.Windows.Forms.GroupBox groupBox1;
     
        }
    }
    et avec un process.exitcode:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     private void EXSEG1_Click(object sender, EventArgs e)
            {
                var psi5 = new ProcessStartInfo();
                psi5.FileName = "notepad.exe";
                psi5.Arguments = @"C:\nam\EXSEG1.nam";
                psi5.Verb = "runas";
     
                var process = new Process();
                process.StartInfo = psi5;
                process.Start();
                process.WaitForExit();
                process.ExitCode();
            }
    avec une erreur : Erreur 1 Un membre 'System.Diagnostics.Process.ExitCode' ne pouvant pas être appelé ne peut pas être utilisé comme une méthode.

    Merci encore pour votre aide

  5. #5
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 196
    Points : 197
    Points
    197
    Par défaut
    faut pas mettre les ()
    faut mettre ça comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    int l = process.ExitCode;
    si l est égale à 0, c'est bon sinon une erreur s'est produite

  6. #6
    Rédacteur
    Avatar de Nathanael Marchand
    Homme Profil pro
    Expert .Net So@t
    Inscrit en
    Octobre 2008
    Messages
    3 615
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Expert .Net So@t
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2008
    Messages : 3 615
    Points : 8 082
    Points
    8 082
    Par défaut
    Effectivement, ca ne peut pas marcher, seul le bouton EXSEG2 possède un gestionnaire d'évènements et pas les autres:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.EXSEG2.Click += new System.EventHandler(this.EXSEG2_Click);

  7. #7
    Membre du Club
    Inscrit en
    Mai 2011
    Messages
    72
    Détails du profil
    Informations forums :
    Inscription : Mai 2011
    Messages : 72
    Points : 49
    Points
    49
    Par défaut
    C'est bon j'ai trouvé (grace à micka132)

    Dans le designer il manquait l'event pour tous les autres boutons

    Merci de votre micka132 et patmat44

  8. #8
    Expert confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2009
    Messages
    2 032
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2009
    Messages : 2 032
    Points : 5 476
    Points
    5 476
    Par défaut
    this.EXSEG2.Click += new System.EventHandler(this.EXSEG2_Click);


    c'est la seule déclaration que je vois .

    Tu vas dans le designer, sur chaque bouton dans la fenetre des propriétés tu te mets sur l'onglet évenement.
    Ensuite dans chaque champs "Click" tu inscrits le nom de la méthode que tu souhaites appeler.


    edit: trop lents

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

Discussions similaires

  1. GWTExt : Button.setStyle ne fonctionne pas
    Par Glenn_31 dans le forum GWT et Vaadin
    Réponses: 4
    Dernier message: 18/03/2009, 12h04
  2. Double formulaire - un seul fonctionne
    Par Gwadadev dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 18/05/2008, 00h13
  3. Limiter un button à 1 seul click
    Par skillipo dans le forum Servlets/JSP
    Réponses: 4
    Dernier message: 19/04/2008, 11h04
  4. [AJAX] [2 menu déroulant] 1 seul fonctionne
    Par Arbisis dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 07/03/2008, 13h11
  5. button:hover ne fonctionne pas sous IE6
    Par mathieugamin dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 16/05/2007, 11h34

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