jeudi 20 octobre 2022

Reflecting a picturebox name and a resource picture using a random number

I have 4 picturebox. The names: pb1, pb2, pb3, pb4 And I have 4 resource file: cards_club, cards_diamon, cards_heart, cards_spades

The resource files contains some french card picture. One of the names is: Cards-6-Club.svg

So my problem is: how to reflect them using a random number.

I mean - here is the main part of the code:

    Random rnd = new Random();
            int color = rnd.Next(1,4+1);
            int value = rnd.Next(1,13+1);
            int pb_num = rnd.Next(1,4+1);
            textBox1.Text=color.ToString()+" "+value.ToString(); //this is just a helper data. It will never show to the user when the program is done
            switch (color) {
                case 1:             
                    if(value>=2 && value<=10){
                        pb??.Image = Projectname.cards_club.(Cards_+VALUE+_Club_svg).ToString();
    
                    }

My problem is: how can I use the previously generated number (stored as pb_num) here pb??.Image = , where the question mark is. And here Projectname.cards_club.(Cards_+value+_Club_svg).ToString(); how can I combine a previously generated random number (stored as value) with the name of the picture? So with this I can get a picture in the picturebox, where a random number (for example 5) shows the exact card. If I get 5 (value = 5) I want to show in the picturebox the Cards-5-Club.svg.

Thank you so much your answers, and please feel free to ask if anything is not exactly clear.




Aucun commentaire:

Enregistrer un commentaire