Bonjour a tous,
J'ai dans mon programme un contrôle numericUpDown. Celui-ci permet suivant la valeur choisi d'affiché un label + un textbox.
Si la valeur du numericUpDown est 1 alors il affiche 1 label et 1 textbox.
Si la valeur est 2 alors il affiche 2 label et 2 textbox.
... etc etc
Jusque la tout vas bien.
Mais si je choisi 1 après avoir choisi 2 j'ai toujours 2 label et 2 textbox.
En gros quand j'incrémente mon numericUpDown il y a le nombre de contrôle voulu mais quand je décrémente les contrôle présent dans mon panel ne bouge pas.
Voici mon code :
Merci a vous pour votre aide.
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 public Form1() { InitializeComponent(); numericUpDownNbrPropriete.Maximum = 10; numericUpDownNbrPropriete.Minimum = 1; numericUpDownNbrPropriete.Value = 1; } private void numericUpDownNbrPropriete_ValueChanged(object sender, EventArgs e) { switch ((int)numericUpDownNbrPropriete.Value) { case 1: Label labelChamp1 = new Label(); TextBox textBoxChamp1 = new TextBox(); labelChamp1.Text = "propriété n° 1 "; panelPropriete.Controls.Add(labelChamp1); panelPropriete.Controls.Add(textBoxChamp1); labelChamp1.Location = new Point(10, 10); textBoxChamp1.Location = new Point(40, 10); break; case 2: Label labelChamp2 = new Label(); TextBox textBoxChamp2 = new TextBox(); labelChamp2.Text = "propriété n° 2 "; panelPropriete.Controls.Add(labelChamp2); panelPropriete.Controls.Add(textBoxChamp2); labelChamp2.Location = new Point(10, 40); textBoxChamp2.Location = new Point(40, 40); break; case 3: Label labelChamp3 = new Label(); TextBox textBoxChamp3 = new TextBox(); labelChamp3.Text = "propriété n° 3 "; panelPropriete.Controls.Add(labelChamp3); panelPropriete.Controls.Add(textBoxChamp3); labelChamp3.Location = new Point(10, 70); textBoxChamp3.Location = new Point(40, 70); break; default: break; } }
Partager