Click here to Skip to main content
15,891,943 members
Home / Discussions / C#
   

C#

 
AnswerRe: how can get a file path when user double click on it such as word files? Pin
pmarfleet15-Oct-07 10:48
pmarfleet15-Oct-07 10:48 
GeneralRe: how can get a file path when user double click on it such as word files? Pin
B.A15-Oct-07 11:04
B.A15-Oct-07 11:04 
QuestionCreating items for CheckedListBox Pin
s3rro15-Oct-07 9:45
s3rro15-Oct-07 9:45 
AnswerRe: Creating items for CheckedListBox Pin
Justin Perez15-Oct-07 10:08
Justin Perez15-Oct-07 10:08 
QuestionProject Resource Pin
mihksoft15-Oct-07 8:00
mihksoft15-Oct-07 8:00 
AnswerRe: Project Resource Pin
Justin Perez15-Oct-07 8:26
Justin Perez15-Oct-07 8:26 
GeneralRe: Project Resource Pin
mihksoft15-Oct-07 8:31
mihksoft15-Oct-07 8:31 
GeneralRe: Project Resource [modified] Pin
Kristian Sixhøj15-Oct-07 9:19
Kristian Sixhøj15-Oct-07 9:19 
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"

QuestionConfiguration settings - Howto? [modified] Pin
Phrone15-Oct-07 7:01
Phrone15-Oct-07 7:01 
AnswerRe: Configuration settings - Howto? Pin
Skippums15-Oct-07 7:16
Skippums15-Oct-07 7:16 
AnswerRe: Configuration settings - Howto? Pin
Justin Perez15-Oct-07 7:30
Justin Perez15-Oct-07 7:30 
QuestionRichTextBox.SelectionBackColor property Pin
Skippums15-Oct-07 6:55
Skippums15-Oct-07 6:55 
AnswerRe: RichTextBox.SelectionBackColor property Pin
mav.northwind15-Oct-07 19:23
mav.northwind15-Oct-07 19:23 
GeneralRe: RichTextBox.SelectionBackColor property Pin
Skippums16-Oct-07 4:18
Skippums16-Oct-07 4:18 
QuestionCatch C++ exception in C# Pin
Not Knuth15-Oct-07 6:35
Not Knuth15-Oct-07 6:35 
AnswerRe: Catch C++ exception in C# Pin
led mike15-Oct-07 6:52
led mike15-Oct-07 6:52 
GeneralRe: Catch C++ exception in C# Pin
Not Knuth15-Oct-07 7:22
Not Knuth15-Oct-07 7:22 
GeneralRe: Catch C++ exception in C# Pin
led mike15-Oct-07 7:45
led mike15-Oct-07 7:45 
GeneralRe: Catch C++ exception in C# Pin
Not Knuth15-Oct-07 8:00
Not Knuth15-Oct-07 8:00 
GeneralRe: Catch C++ exception in C# Pin
led mike15-Oct-07 8:05
led mike15-Oct-07 8:05 
GeneralRe: Catch C++ exception in C# Pin
Not Knuth15-Oct-07 8:15
Not Knuth15-Oct-07 8:15 
AnswerRe: Catch C++ exception in C# Pin
Liam O'Hagan15-Oct-07 20:57
Liam O'Hagan15-Oct-07 20:57 
GeneralRe: Catch C++ exception in C# Pin
Not Knuth16-Oct-07 5:26
Not Knuth16-Oct-07 5:26 
AnswerRe: Catch C++ exception in C# Pin
Marshall16-Oct-07 6:11
Marshall16-Oct-07 6:11 
GeneralRe: Catch C++ exception in C# Pin
Not Knuth16-Oct-07 7:47
Not Knuth16-Oct-07 7:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.