[Debutant]Afficher element du tableau avec Random

Afficher element du tableau avec Random [Debutant] - C#/.NET managed - Programmation

Marsh Posté le 29-01-2008 à 23:57:35    

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.

Code :
  1. /* DONNEES DE TRAVAIL */
  2.         int iI = 0;
  3.        
  4.          /* Le Fonction */
  5.         private void b1DemarrerForm2_Click(object sender, EventArgs e)
  6.         {
  7.             Random rndm1, rndm2, rndm3;
  8.             rndm1 = new Random(unchecked((int)DateTime.Now.Ticks));
  9.             rndm2 = new Random(unchecked((int)DateTime.Now.Ticks));
  10.             rndm3 = new Random(~unchecked((int)DateTime.Now.Ticks));
  11.             string[] sTab = {"LIVRES", "FRUITS", "ANIMAUX", "GAZ", "BANQUE"};
  12.             label4Form2.Text = string.Empty;
  13.             label5Form2.Text = string.Empty;
  14.             label6Form2.Text = string.Empty;
  15.             for (iI = 0; iI < 5; iI++)
  16.             {
  17.                 int iRand1 = rndm1.Next(5);
  18.                 int iRand2 = rndm2.Next(5);
  19.                 int iRand3 = rndm3.Next(5);
  20.                 label4Form2.Text = sTab[iRand1];
  21.                 label5Form2.Text = sTab[iRand2]; 
  22.                 label6Form2.Text = sTab[iRand3];
  23.             }
  24.         }


Ce que je voulais, comment afficher ces elements du tableau de façon aleatoire sur chaqu'un de ces labels.
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.

Reply

Marsh Posté le 29-01-2008 à 23:57:35   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed