Hello, I have difficulties with showing multiple (up to 5) pictureboxes on top each other, but able to see all of them. Only first and last will show up. I show them from bottom to top, set their locations correctly and using BringToFront() function. Does anybody have a solution (if any)? Thanks for help!
+2
A:
Not sure what the actual problem is; the following code adds 5 stacked PictureBox
es to a form, and configures them so they are all visible.
private void AddStackedPictureBoxes()
{
for (int i = 0; i < 5; i++)
{
PictureBox pb = new PictureBox();
pb.BackColor = Color.FromArgb(i * 50, i * 50, i * 50);
pb.BorderStyle = BorderStyle.FixedSingle;
pb.Location = new Point(i * 10, i * 10);
pb.Size = new Size((5 - i) * 20, (5 - i) * 20);
Controls.Add(pb);
pb.BringToFront();
}
}
Perhaps that will give you some insight into why you are having problems.
For example, if you call BringToFront()
before the control is added to the form, it won't have any effect.
Daniel LeCheminant
2009-03-25 20:12:21
thanks, the problem was that I added them *after* using BringToFront() ... didn't realized until now (bad habit from VS Form Desinger - set all properties, then add to panel/form etc.)
2009-03-25 20:17:36
You also need to make sure your pictureboxes are added to the same control. I was going crazy wondering why a picturebox added to the main form wouldn't go under a picturebox added to a panel. Whoops!
ashes999
2010-10-23 23:21:29
A:
Be sure to set background color to transparent on each of them.
and as Daniel said, BringToFront() only works if the control is already on a form.
Neil N
2009-03-25 20:14:45
well I don't know why I should do that (with transparent color). I draw pictures with no transparent regions/areas whatsoever.
2009-03-25 20:42:05
Well I assumed the reason you'd stack them is so that you can have a layered effect.
Neil N
2009-03-25 21:15:09