重叠的PicuresBox有透明背景

时间:2013-01-08 10:21:37

标签: c# winforms image picturebox

我希望使用透明背景制作两个或更多重叠的PictureBox,但如果我这样做,我只会看到一张图片:

enter image description here

我创建我的PictureBox es:

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;

稍后我将这两个PictureBox es添加到我的Panel

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

那为什么它只显示一个PictureBox

2 个答案:

答案 0 :(得分:0)

尝试将panel1.Controls.Add(pb2);更改为pb1.Controls.Add(pb2);
确保将pb1设置为正确的位置

答案 1 :(得分:-1)

如果你的human.png有透明背景:

pb2.BackColor = Color.Transparent;