3

I want make two or more overlapping PictureBox with transparent background but if I do this I see only one Image:

enter image description here

I create my PictureBoxes like this:

PictureBox pb1 = new PictureBox();
pb1.Size = new Size(32, 32);
pb1.Location = new Point(0,0);
pb1.Image = Image.FromFile("../Graphics/Grounds/ground.png");
pb1.Visible = true;

PictureBox pb2 = new PictureBox();
pb2.Size = new Size(32, 32);
pb2.Location = new Point(0,0);
pb2.Image = Image.FromFile("../Graphics/Grounds/human.png");
pb2.Visible = true;

Later I add those two PictureBoxes to my Panel:

panel1.Controls.Add(pb1);
panel1.Controls.Add(pb2);

So why does it only shows one PictureBox?

Jacek Grzelaczyk
  • 783
  • 2
  • 9
  • 21

2 Answers2

0

Try change panel1.Controls.Add(pb2); to pb1.Controls.Add(pb2);
Make sure you set the correct location as pb1 be the container

Michael Yuwono
  • 2,452
  • 1
  • 14
  • 32
-1

If your human.png has transparent background:

pb2.BackColor = Color.Transparent;
gunakkoc
  • 1,069
  • 11
  • 30
  • 1
    no, the main problem here is that the human picturebox should be inserted as a groundPicBox's subControl, as reported here http://stackoverflow.com/a/9158849/838405 and on Hans Passant answer – Tobia Zambon Jan 08 '13 at 15:04