Bonjour,
voici mon problème.
J'ai mon Form1 qui est l'application principale.
J'ai créé un UserControl que j'ai intégré dans un Form2(StartIcones) et qui permet à l'utilisateur de faire un choix entre 3 rubriques. Ces rubriques sont symbolisées par des icônes.
Je voudrais que mon Form1 récupère le choix fait par l'utilisateur.
j'ai donc utilisé un delegate et un event.
Si je n'utilise pas de UserControl et fais mon design directement dans mon Form2, pas de problème je récupère correctement le choix de l'utilisateur.
Mais.. dans le cas d'un UserControl importé dans le Form2(StartIcones) cela ne fonctionne plus.
Le Form1 ne récupère plus le choix fait dans le Form2(UserControl)
J'ai mis mon delegate et mon event directement dans le code behind de mon UserControl. Ce qui donne ceci:
et mom Form1 "s'abonne" à l'événement.Code:
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 public partial class MenuPanel : UserControl { public delegate void EChoixApplication(string reponse); public event EChoixApplication monEvent; public MenuPanel() { InitializeComponent(); } // => Bouton Caisse public void PCTBCaisse_Click(object sender, EventArgs e) { if (monEvent != null) { monEvent(string.Format("{0}", PCTBCaisse.Tag)); } } // => Bouton Compta public void PCTBCompta_Click(object sender, EventArgs e) { if (monEvent != null) { monEvent(string.Format("{0}", PCTBCompta.Tag)); } } // => Bouton Administration public void PCTBAdmin_Click(object sender, EventArgs e) { if (monEvent != null) { monEvent(string.Format("{0}", PCTBAdmin.Tag)); } } }
Auriez-vous une idée?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public Form1() { InitializeComponent(); StartIcones i = new StartIcones(); i.Show(); i.monEvent += new StartIcones.EChoixApplication(ChoixApplication); } // Récupération du choix dans une TextBox public void ChoixApplication(string reponse) { textBox1.Text = reponse; } }
Merci