Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanna create an array of picturebox controls, so I used a panel to hold them. However, afterwards I found that the Image has been disabled. Do I have to use BackgroundImage instead? :(
Posted

the code below, creates an 10 index array of PictureBox, and assign their Sizes, Locations, Names, Images and put them on a panel in a row. may be you can use it somehow :

<br />
           PictureBox[] Pix = new PictureBox[10];<br />
           for (int i = 0; i < 10; i++)<br />
           {<br />
               Pix[i] = new PictureBox();<br />
               Pix[i].Image = Image.FromFile(@"C:\bmp.bmp");<br />
               Pix[i].SizeMode = PictureBoxSizeMode.StretchImage;<br />
               Pix[i].Name = string.Format("Image{0}", i);<br />
               Pix[i].Size = new Size(10, 10);<br />
               Pix[i].Location = new Point(i * 10, 0);<br />
               panel1.Controls.Add(Pix[i]);<br />
           }<br />


----------------------
Regards

H.Maadani
 
Share this answer
 
I think from reading between the lines that you have:

1) Constructed a panel
2) Dynamically created an array of PictureBox controls, each to display an image.
3) Tried to set the Image property, and been told it doesn't exist, so are trying to use the BackgroundImage property instead.

This implies that what you tried was
Panel1.Image = new Image(@"c:\...
but the compiler complained.
A Panel control does not have an Image property (irt does have a BackgroundImage, but this is not what you want). What you need to do is set the Image property of each PictureBox control instead.

Have you added the PictureBox controls to the Panel.Controls list?
Have you given them all new Location properties, and appropriate sizes?
If you have many images, you may be better off drawing them yourself with the Paint event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900