3 Replies - 637 Views - Last Post: 05 October 2012 - 12:37 PM Rate Topic: -----

#1 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Single image, multiple pictureboxes

Posted 04 October 2012 - 05:02 PM

I have 1 picturebox loaded with an image, what i'm trying to do is every time i click on loaded image the same picture loads into empty picturebox. Now for 1 picturebox is easy, all i do is picturebox1.Image = img;

I'm trying to make an event that will load image to next empty picture box
This code is in the picturebox.click event that is loaded with image
int counter = 0;
            
            List<PictureBox> pbox= new List<PictureBox>(); //Holds list of PictureBoxes that will be loaded(currently there are 28)
            PictureBox img = ((PictureBox) sender); //Holds the image that i clicked
            
            
            foreach (Control ctrl in groupBox1.Controls) //Enumerate all controls and add them to the list
            {
                if (ctrl is PictureBox)
                {                    
                    pbox.Add((PictureBox) ctrl);
                }
                              
            }
            pbox[counter] = img; //loads the image to the first picturebox in list
            pictureBox1.Image = pbox[counter].Image; // Now this should load  the image (i need help with this), what should i use instead picturebox1.Image
            counter++;


Is This A Good Question/Topic? 0
  • +

Replies To: Single image, multiple pictureboxes

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: Single image, multiple pictureboxes

Posted 05 October 2012 - 05:20 AM

What does your form look like, and what exactly are you trying to do with it? How many PictureBoxes do you have? I need to see more code before I can help you more.

Also, you need to make a separate function for the action, and call that function from your event handler, rather than include all of that code in the event handler itself.
Was This Post Helpful? 0
  • +
  • -

#3 teyrebaz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 14-January 12

Re: Single image, multiple pictureboxes

Posted 05 October 2012 - 06:21 AM

hi,

define a global variable // i assume its 'counter'

counter=0;


drag a imagelist on your form and

in your evet;

picturebox[0].Image=imageList1.Image[counter]; // u are assign images from imagelist to your picturebox- if u want to assign your image to next picturebox change code like this;

picturebox[counter].Image=imageList1.Image[counter]; // next image to next picturebox.. if u want to assign just one of your image to next picturebox change code like this;

picturebox[counter].Image=imageList1.Image[YOURIMAGEINDEX];

counter++; // increasing variable for every clicking act that we can use in assignment operation

Was This Post Helpful? 0
  • +
  • -

#4 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: Single image, multiple pictureboxes

Posted 05 October 2012 - 12:37 PM

I'm trying to make the Mastermind game, already have the text version but replacing text version for image version is little bit harder.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1