Salut, je voulais vous demander une aide que je n'ai pas pu resoudre car je suis debute pour programmation C# en plus de ça je dois faire en mode application. Voici mon problemme: Je voulais afficher chaque élément du tableau sur de ces 3 labels. J'ai dispose 3 labels et 5 elements du tableau de type string.
Ce que je voulais, comment afficher ces elements du tableau de façon aleatoire sur chaqu'un de ces labels.
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 /* DONNEES DE TRAVAIL */ int iI = 0; /* Le Fonction */ private void b1DemarrerForm2_Click(object sender, EventArgs e) { Random rndm1, rndm2, rndm3; rndm1 = new Random(unchecked((int)DateTime.Now.Ticks)); rndm2 = new Random(unchecked((int)DateTime.Now.Ticks)); rndm3 = new Random(~unchecked((int)DateTime.Now.Ticks)); string[] sTab = {"LIVRES", "FRUITS", "ANIMAUX", "GAZ", "BANQUE"}; label4Form2.Text = string.Empty; label5Form2.Text = string.Empty; label6Form2.Text = string.Empty; for (iI = 0; iI < 5; iI++) { int iRand1 = rndm1.Next(5); int iRand2 = rndm2.Next(5); int iRand3 = rndm3.Next(5); label4Form2.Text = sTab[iRand1]; label5Form2.Text = sTab[iRand2]; label6Form2.Text = sTab[iRand3]; } }
Remarque: à moment donner le resultat de ces 3 labels doit être tous le meme.
EX: Label1 = ANIMAUX Label2 = GAZ Label3 = BANQUE
La suite de l'execution
Label1 = FRUITS Label2 = FRUITS Label3 = LIVRES
La suite de l'execution
Label1 = BANQUE Label2 = BANQUE Label3 = BANQUE
Merci D'avance.
Partager