jeudi 4 février 2016

How to display a random image from a list, everytime the button is pressed ? C#

So I'm totally new to C# and I've been building a "Character Generator" for a tabletop RPG. I've assigned a button with the task of generating a new story every time it is pressed. I've downloaded a huge collection of character portraits which I'd like to display in this little app of mine to give some inspiration to the user.

I thought that using a button I could have the app select a different image in the aforementioned list every time it is pressed.

I tried this:

private void button1_Click(object sender, EventArgs e)
{
        List<String> paths = new List<String>();
        Random random = new Random();
        paths.Add(Project1.Cartes.Portrait);
        pictureBox1.ImageLocation = paths[random.Next(0, images.Count - 1)];

I get two errors: Project1.Cartes.Portrait is an invalid namespace, and the name "images" does not exist.

I can't mention every image, since there are 500 of them. So I need the app to instead take a random image from a specific location. Any ideas ?




Aucun commentaire:

Enregistrer un commentaire