R – PictureBoxes and Zorder [.NET]


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!

Best Solution

Not sure what the actual problem is; the following code adds 5 stacked PictureBoxes 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);



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.