pictureBox Dynamisch verwenden?!

BFreakout

Erfahrenes Mitglied
Hallo@all,

mein Problem ist folgendes.. ich habe 6 pictureBoxen auf meiner Form... und jede PictureBox soll aber eine zufällig Generierte Zahl von Bild Öffnen... nur erlaubt es der Compiler nicht..

Code:
 public void KarteAnzeigen(int Karte)
        {

            PictureBox[] pictureBox = { pictureBox1, pictureBox1, pictureBox2, pictureBox3 };
            pictureBox[Karte].Image = global::WinMemory.Properties.Resources._2;
        }

 private void pictureBox2_Click(object sender, EventArgs e)
        {
            KarteAnzeigen(2);
        }

und anstatt _2 also bei Resources soll eine Zufallszahl stehen...

würd mich um hilfe freuen....
 
Sodala... habs geschafft aber nicht mit den Resource Images... sondern:

Code:
 // *****************
 // * KarteAnzeigen *
 // *****************
        public void KarteAnzeigen(int Karte)
        {
            PictureBox[] pictureBox = { pictureBox1, pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6, pictureBox7, pictureBox8, pictureBox9, pictureBox10, pictureBox11, pictureBox12 };
            
            int Bild = Bilder[Karte];
            pictureBox[++Karte].Image = new Bitmap (@Bild+".jpg");

Karte ist der Angeklickte Kartenwert... und Bilder ist die Array mit denn Generierten Bildern...

Was meine Frage sonst wäre, wie kann ich ein Random auf meine Array Bilder mit den werten 1-6 einfügen das jede zahl auf 12 Felder nur 2 mal vorkommt und jede auch sicher dabei ist?

z.B. Array[...]
[0] = 1
[1] = 2
[2] = 4
[3] = 5
[4] = 3
[5] = 6
[6] = 1
[7] = 4
[8] = 2
[9] = 3
[10] = 5
[11] = 6

So sieht der Code bei mir aus:

Code:
// *****************
// * KartenMischen *
// *****************
        public void KartenMischen()
        {
           for (int i = 0; i <= 11; i++)
           {
                //Zufallsgenerator 1-6
                Random r = new Random();
                int m = (r.Next(7));
                
                if (m == 0) //Damit keine 0 ins Array kommt...
                {
                    i--;
                }
                else
                {
                    Bilder[i] = m;
                }       
           }
        }
 
Zurück