Project Resource
-
Hy, I have 3 pictures in a project resource, a picturebox and a button. I want when I press the button to change dynamic the pictures from picturebox. Can anybody help me? thx
Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
-
Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
-
It's not a task is for my knowledge. I want to place random image from the project resource to my picturebox.that's it :D
Create an array, and put the images from the project resource in it.
// 5 means there are five images. Change it if you need to.
Image[] images = new Image[5];Then create an object of type System.Random:
Random ran = new Random();
^ These two must be defined outside a method. Then do the following in your button event handler:
// fill the array with images
images[0] = Properties.Resources.Image1; // Image1 is the name of the image
images[1] = Properties.Resources.Image2;
images[2] = Properties.Resources.Image3;
images[3] = Properties.Resources.Image4;
images[4] = Properties.Resources.Image5;// generate a random integer below 5
int pic = ran.Next(5);pictureBox1.Image = images[pic];
And that should do the trick. Edit: Perhaps it would be better to fill up the array in the form's constructor (usually
public Form1()
):public Form1()
{
InitializeComponent();
images[0] = Properties.Resources.Image1;
images[1] = Properties.Resources.Image2;
// and so on..
}Virtual1ty
"Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"