views:

324

answers:

3

the following is an example of test code, it maybe not be completely correct:

        for (int i = 0; i < MAXCOL; i++)
        {
            for (int j = 0; j < MAXROW; j++)
            {
                HomeArrayPicBox[i, j].Image  = Properties.Resources.scan;
            }
        }

my issue is instead of all pictureboxes displaying the same picture, i need to increment the image also. e.g. Properties.Resources.scan1, Properties.Resources.scan2 ...

please adive how best to achive this.

thank you.

A: 

Make scan an array of image resources, and on each iteration, determine the correct index of that array to populate the picture box with.

NickLarsen
A: 

You can put all image object you need in an array. The length of this array should be MAXCOL * MAXROW. I assume you have the same number of images as boxes? Than you could iterate trough this array.

Bright010957
+3  A: 

You can get an object from a Resources file by name like this:

HomeArrayPicBox[i, j].Image = 
    (Image)Properties.Resources.ResourceManager.GetObject("Scan" + i);
SLaks
I haven't tried this before...just curious, do you need to do a typecast here when pulling the object from the resourcemanager?
Aaron
Yes; I forgot that. Thanks.
SLaks
i get an error: Cannot implicitly convert type 'object' to 'System.Drawing.Image'. An explicit conversion exists (are you missing a cast?)
iEisenhower
I forgot to include `(Image)`. Try it again now.
SLaks
ok now it works. had to cast to image.
iEisenhower