相关疑难解决方法(0)

C#Picturebox透明背景似乎不起作用

对于我的项目,我需要使用透明背景显示图像.我制作了一些具有透明背景的.png图像(为了检查这一点,我在Photoshop中打开它们).现在我有一个扩展PictureBox的类:

class Foo : PictureBox
{
    public Foo(int argument)
        : base()
    {
        Console.WriteLine(argument);//different in the real application of course.
        //MyProject.Properties.Resources.TRANSPARENCYTEST.MakeTransparent(MyProject.Properties.Resources.TRANSPARENCYTEST.GetPixel(1,1)); //<-- also tried this
        this.Image = MyProject.Properties.Resources.TRANSPARENCYTEST;
        ((Bitmap)this.Image).MakeTransparent(((Bitmap)this.Image).GetPixel(1, 1));
        this.SizeMode = PictureBoxSizeMode.StretchImage;
        this.BackColor = System.Drawing.Color.Transparent;
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,这只是显示带有白色背景的图片框,我似乎无法使其与透明背景一起工作.

c# transparency picturebox

18
推荐指数
3
解决办法
9万
查看次数

标签 统计

c# ×1

picturebox ×1

transparency ×1