我需要帮助理解Windows窗体中的透明度顺序。我创建了一个简单的表单,其中没有任何内容称为test。
在表单的构造中,我创建了一个面板和一张如下图片:
public partial class test : Form
{
public test()
{
InitializeComponent();
//create a panel
Panel panel = new Panel();
panel.Location = new Point(10, 10);
panel.Size = new Size(100, 100);
panel.BackColor = Color.FromArgb(255, 0, 0);
panel.Show();
//put panel on screen
this.Controls.Add(panel);
//create a picture box
PictureBox picture = new PictureBox();
picture.ImageLocation = "../myPicture2.png";
picture.Location = new Point(20, 20);
picture.Size = new Size(100, 100);
picture.BackColor = Color.Transparent;
picture.Show();
this.Controls.Add(picture);
picture.BringToFront();
}
}
起初我使用的图像是myPicture1.png
,带有白色背景的图像给我这个结果。
然后我用gimp裁剪出白色背景,使其成为透明背景。
但是,现在表单的背景显示而不是面板。
当我将这个PictureBox放在面板顶部时,我试图将面板的背景颜色保留在Image后面。
像这样:
有人可以向我解释如何实现在图片框中透明图像背后的面板背景所需的效果吗?所有建议都一如既往地受到高度赞赏!
答案 0 :(得分:1)
这个问题不是由于图片框在图片上而不是在面板内造成的吗?
panel.Controls.Add(picture);