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 :

Paramètre entre deux forms [Débutant]


Sujet :

C#

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Points : 52
    Points
    52
    Par défaut Paramètre entre deux forms
    Bonjour

    Je sais que la question est traité dans plusieurs post mais malheureusement pas comme dans la situation ou plutot je n'arrive pas à mettre en place les différents solution...

    Voila j'ai une fenetre principal crée ainsi dans programme.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
     
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
     
    namespace KMP_WT
    {
        static class Program
        {
            /// <summary>
            /// Point d'entrée principal de l'application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault( false );
                Application.Run( new CFormWT() );
            }
        }
    }
    Sur un des onglets de cette fenêtre j'ai le bouton qui ouvre une autre fenetre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    private void TestDiaolog_Clicked(object sender, EventArgs e)
            {
                Form Marquage =new CForm_Popup();
                Marquage.ShowDialog();
            }
    Dans cette nouvelle fenêtre j'ai 3 bouton dont je voudrais qu'ils puissent interagir avec le label Statut definit comme telle

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public System.Windows.Forms.Label Statut;
    J'ai essaye de l'appel comme telle this.Statut.Text KMP_WP.CFormWT.Statut.Text etc... mais ca donne rien.

    Je n'arrive pas à voir comment le faire...
    (Je reprend du code d'un collègue...)

    Merci de votre aider

  2. #2
    Membre expérimenté Avatar de callo
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 887
    Points : 1 699
    Points
    1 699
    Par défaut
    Bonjour,
    Je n'arrive pas à bien te suivre là...Ton label Statut se trouve dans quel form?
    N'oubliez pas le tag et

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Points : 52
    Points
    52
    Par défaut
    Désolé j'ai essayé d'etre au plus claire : )

    Le label statut ce trouve dans la form lancé par

    Application.Run( new CFormWT() )

    et je veux pouvoir le modifier dans la form Marquage

  4. #4
    Membre expérimenté Avatar de callo
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 887
    Points : 1 699
    Points
    1 699
    Par défaut
    Il y a plusieurs façons de procéder. Généralement, moi je procède par soit:
    - passer des paramètres via une surcharge du constructeur du formulaire
    - via des propriétés créer dans le formulaire.

    Dans ton cas, tu pourrais faire un truc du genre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public partial class CFormWT: Form
    {
            // ....
     
            public void UpdateLabelStatut (string valeurLabel)
    	{
    	    this.Statut.Text= valeurLabel;
    	}
    	private void MonBouton_Clicked(object sender, EventArgs e)
            {
                CForm_Popup maform=new CForm_Popup(this);
                maform.ShowDialog();
            }
    }
    Dans le formulaire CForm_Popup, tu pourrais faire:
    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
     
    public partial class CForm_Popup: Form
    { 
    	private CFormWT _frmWT;
     
            public CForm_Popup()
            {
                InitializeComponent();
            }
     
            public CForm_Popup(CFormWT frmWT)
            {
                InitializeComponent();
                this._frmWT = frmWT;
            }
    }
    Sur clique d'un bouton de la form CForm_Popup, tu pourras alors faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this._frmWT.UpdateLabelStatut("Une valeur");
    Ceci mettra à jour le label Statut de la form CFormWT.
    N'oubliez pas le tag et

  5. #5
    Membre du Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2011
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Mars 2011
    Messages : 50
    Points : 68
    Points
    68
    Par défaut
    bonjour,

    je te conseille de passer un paramétre au constructeur de CForm_Popup par exemple une variable de type string et aprés modifier la comme tu veux dans ta fenetre CForm_Popup et ensuite aprés Marquage.ShowDialog(); met à jour ton label en se basant sur la variable.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    private void TestDiaolog_Clicked(object sender, EventArgs e)
            {
                String status;
                Form Marquage =new CForm_Popup(status);
                Marquage.ShowDialog();
                tonlabel.text = status;
            }
    Attention il faut que crée un autre constructeur dans ta fenetre qui prend un parametre de type string.
    Vous avez la réponse à votre question ? Mettez votre sujet en

    Une personne vous a correctement aidé ? Cliquez sur le +1

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Points : 52
    Points
    52
    Par défaut
    Citation Envoyé par callo Voir le message
    Il y a plusieurs façons de procéder. Généralement, moi je procède par soit:
    - passer des paramètres via une surcharge du constructeur du formulaire
    - via des propriétés créer dans le formulaire.

    Dans ton cas, tu pourrais faire un truc du genre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public partial class CFormWT: Form
    {
            // ....
     
            public void UpdateLabelStatut (string valeurLabel)
    	{
    	    this.Statut.Text= valeurLabel;
    	}
    	private void MonBouton_Clicked(object sender, EventArgs e)
            {
                CForm_Popup maform=new CForm_Popup(this);
                maform.ShowDialog();
            }
    }
    Dans le formulaire CForm_Popup, tu pourrais faire:
    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
     
    public partial class CForm_Popup: Form
    { 
    	private CFormWT _frmWT;
     
            public CForm_Popup()
            {
                InitializeComponent();
            }
     
            public CForm_Popup(CFormWT frmWT)
            {
                InitializeComponent();
                this._frmWT = frmWT;
            }
    }
    Sur clique d'un bouton de la form CForm_Popup, tu pourras alors faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this._frmWT.UpdateLabelStatut("Une valeur");
    Ceci mettra à jour le label Statut de la form CFormWT.
    J'ai commenc2 par ta solution mais il me donne une erreur de compilation "accessibilité incohérente: le type de paramètre 'KMP_WT.CFormWT' est moins accessible que la méthode 'KMP_WT.CForm_Popup.CForm_Popup(KMP_WT.CFormWT)

    Une idée de comment le résoudre?

  7. #7
    Membre expérimenté Avatar de callo
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 887
    Points : 1 699
    Points
    1 699
    Par défaut
    Je ne peux rien dire si tu ne postes pas le code que tu as écrit...
    N'oubliez pas le tag et

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Points : 52
    Points
    52
    Par défaut
    CForm_Popup.Form

    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
     
    namespace KMP_WT
    {
        public partial class CForm_Popup : Form
        {
            private CFormWT _frmWT;
     
            public CForm_Popup(CFormWT frmWT)
            {
                InitializeComponent();
                this._frmWT = frmWT;
            }
     
            private void CForm_Popup_Load(object sender, EventArgs e)
            {
     
            }
     
            private void Begin_Click(object sender, EventArgs e)
            {
                this._frmWT.UpdateLabelStatut("Une valeur");
            }
     
            private void Add_Click(object sender, EventArgs e)
            {
                this.Close();
            }
     
            private void Cancel_Click(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }
    et le fichier CFormWT.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
     
    using System;
    using System.Collections.Generic;
     
    //using System.Data;            //facultatif
    using System.Runtime.InteropServices;
     
    using System.Windows.Forms;
    using System.ComponentModel;    //pour les tris de DataGridView
     
    using System.Text;              //pour Encoding.GetEncoding( "iso-8859-1" )
    using System.Drawing;           //pour changer les "Color"
    using System.IO;                //pour Fichiers et répertoires
    using System.Diagnostics;       //pour Process
    using System.Collections;       //pour ArrayList
    using System.Net;               //pour HttpWebRequest
    using System.Globalization;     //pour CultureInfo, NumberFormatInfo
    using System.Threading;         //pour Thread.Sleep; Thread.CurrentThread.CurrentCulture
     
    using System.Resources;         //pour multilangue
     
    using System.Security.Cryptography; //pour MD5
     
    using System.Security.Principal;
     
    using System.Management;  //pour Accès au réseau,
    //                        //pour lire les Mac adresses, les adresses IP, ...
     
     
    namespace KMP_WT
    {
        internal partial class CFormWT : Form
        {
            private void Automatique_Radio_CheckedChanged(object sender, EventArgs e)
            {
                if (this.Automatique_Radio.Checked)
                {
                    this.ValeurCompotage1.ReadOnly = true;
                    this.ValeurCompotage2.ReadOnly = true;
                    this.ValeurCompotage3.ReadOnly = true;
                    this.ValeurCompotage4.ReadOnly = true;
                }
     
            }
     
            private void Manuel_Radio_CheckedChanged(object sender, EventArgs e)
            {
                if(this.Manuel_Radio.Checked)
                {
                    this.ValeurCompotage1.ReadOnly = false;
                    this.ValeurCompotage2.ReadOnly = false;
                    this.ValeurCompotage3.ReadOnly = false;
                    this.ValeurCompotage4.ReadOnly = false;
                }
            }
     
            private void TestDiaolog_Clicked(object sender, EventArgs e)
            {
                Form Marquage =new CForm_Popup(this);
                Marquage.ShowDialog();
            }
     
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (this.progressBar1.Value % 2 == 0)
                    ValeurCompotage4.BackColor = System.Drawing.Color.Goldenrod;
                else
                    ValeurCompotage4.BackColor = System.Drawing.Color.Fuchsia;
                if (this.progressBar1.Value < this.progressBar1.Maximum)
                {
                    this.progressBar1.Value++;
                    this.Statut.ForeColor = System.Drawing.Color.Green;
                    this.Statut.Text = "en cours";
                }
                else
                {
                    this.timer1.Stop();
                    this.Statut.ForeColor = System.Drawing.Color.Red;
                    this.Statut.Text = "arrêter";
                }
                if (this.Fixe_Radio.Checked == true)
                    ValeurCompotage4.Text = "Job n°";
                else if(this.Variable_Radio.Checked == true)
                    ValeurCompotage4.Text = "Pli n°" + this.progressBar1.Value;
            }
     
            private void Reset_Click(object sender, EventArgs e)
            {
                this.progressBar1.Value = 0;
                this.timer1.Start();
            }
            public void UpdateLabelStatut(string valeurLabel)
            {
                this.Statut.Text=valeurLabel;
            }
     
        } //fin: class(...)
     
     
    } //fin: namespace ...

  9. #9
    Membre expérimenté Avatar de callo
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 887
    Points : 1 699
    Points
    1 699
    Par défaut
    Bah, c'est normal que ça plante puisque tu as mis ton form CFormWT.cs en internal, je veux parler de cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    internal partial class CFormWT : Form
    . Je te laisse découvrir par toi même l'effet de internal ici.

    Pour que ça marche, tu dois avoir:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public partial class CForm_Popup : Form
    .
    N'oubliez pas le tag et

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Points : 52
    Points
    52
    Par défaut
    Oui j'ai vu ca en testant un peu merci pour tout

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

Discussions similaires

  1. [VB.NET] Passer une valeur de control entre deux form
    Par TheMacleod dans le forum Windows Forms
    Réponses: 5
    Dernier message: 27/12/2005, 11h07
  2. [VB .Net][Forms] Interaction entre deux forms
    Par plasticgoat dans le forum Windows Forms
    Réponses: 7
    Dernier message: 24/08/2005, 13h14
  3. [VB.NET] Perte de focus entre deux form
    Par toniolol dans le forum Windows Forms
    Réponses: 2
    Dernier message: 05/07/2005, 08h00
  4. Réponses: 7
    Dernier message: 30/12/2004, 12h01
  5. [jsp][servlet]passage de paramètre entre deux frames
    Par alexandra_ape dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 29/06/2004, 11h14

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