Dialogue entre form

olibara Messages postés 666 Date d'inscription dimanche 16 décembre 2007 Statut Membre Dernière intervention 11 mars 2010 - 18 mars 2008 à 15:12
olibara Messages postés 666 Date d'inscription dimanche 16 décembre 2007 Statut Membre Dernière intervention 11 mars 2010 - 22 avril 2008 à 16:34
Afin de pouvoir dialoguer entre deux form, Il me semble que c'est a coup d'event et sans doute de quelque variables a passer que je dois travailler


MAIS MAIS MAIS : je n'ai AUCUNE experience de declaration et d'exploitation d'event ?


Que dois je faire au minimum dans deux form Form1 et Form2 pour que Form2 genere un event qui appelle une fonction dans Form1, sachant que c'est Form1 qui instancie Form2  ?
         

3 réponses

olibara Messages postés 666 Date d'inscription dimanche 16 décembre 2007 Statut Membre Dernière intervention 11 mars 2010 6
18 mars 2008 à 16:08
J'ai trouvé un truc pas mal

Certainement plus que l'explication elementaire mais un bon exemple

http://www.codeproject.com/KB/cs/PassDataWinForms.aspx
0
Liverion Messages postés 296 Date d'inscription mardi 22 avril 2008 Statut Membre Dernière intervention 18 août 2008
22 avril 2008 à 16:19
Sinon tu as toujours la solution de passer la fenetre appelante dans le constructeur de la fenetre appelée et d'appeler une fonction publique de la fenetre appelante :

(Ici j'ai une fenetre principale MainWindows et une petit fenetre secondaire GeschwindigkeitForm pour choisir un parametre )

namespace SimulatorClient
{
    public partial class MainWindows : Form
    {
        /// <summary>
        /// Variable to create the windows for choosing sending speed
        /// </summary>
        private SimulatorClient.GeschwindigkeitForm speedForm;

        /// <summary>
        /// Function called by the speed form
        /// </summary>
        ///
        /// number of data per second
        ///

        public void changeSpeed(int value)
        {
            if (value != 0)
            {
                timer1.Interval = 1000 / value;
                speedLabel.Text = value.ToString();
            }          
         }
    }
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

namespace SimulatorClient
{
    /// <summary>
    /// Secondary windows, only to choose the speed
    /// </summary>
    public partial class GeschwindigkeitForm : Form
    {
        /// <summary>
        /// Variable to get the calling windows
        /// </summary>
        private MainWindows caller;

        /// <summary>
        /// Constructor for the Form
        /// </summary>
        ///
        /// Get the parent Form
        ///

        public GeschwindigkeitForm(MainWindows value)
        {
            InitializeComponent();
            caller = value;
        }

        /// <summary>
        /// Button ok event handler
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            // if some value is written when clicking on "Ok"
            if (textBox1.Text != "")
            {
                try
                {
                    // if the value is bigger than 0 and smaller than 251
                    if (int.Parse(textBox1.Text) > 0 && int.Parse(textBox1.Text) <= 250)
                    {
                        // call the parent's method changeSpeed(int value)
                        caller.changeSpeed(int.Parse(textBox1.Text));
                        // hide the windows
                        Hide();
                    }
                    // else say to enter a value in the valid range
                    else MessageBox.Show("Es ist kein richtiges Nummer");
                }
                // if a FormatException is thrown
                catch(FormatException ex)
                {
                    ex.ToString();
                    // Say to enter a number
                    MessageBox.Show("Bitte schreiben Sie ein Nummer");
                }
            }
            // if no value is written when clicking on "Ok"
            else
            {
                // ask for entering a value
                MessageBox.Show("Bitte schreiben Sie etwas");
            }
        }
   }
}

Si ca peut t'aider
0
olibara Messages postés 666 Date d'inscription dimanche 16 décembre 2007 Statut Membre Dernière intervention 11 mars 2010 6
22 avril 2008 à 16:34
Merci,

C'est effectivement ce que j'ai fait
Facile pour les cas simples
0
Rejoignez-nous