C#图片框透明的背景似乎不工作 [英] C# Picturebox transparent background doesn't seem to work

查看:843
本文介绍了C#图片框透明的背景似乎不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的项目,我需要的图像具有透明背景来显示。我提出,有一个透明背景的一些png格式图片(检查这个我在Photoshop中打开它们)。现在我有一个扩展的PictureBox类:

For a project of mine I need images to display with a transparent background. I made some .png images that have a transparent background(to check this I opened them in Photoshop). Now I have a class that extends 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;
    }
}

然而,这只是显示一个白色背景图片框,我似乎无法使它具有透明背景的工作。

this however just displays the picturebox with a white background, I just can't seem to make it work with a transparent background.

推荐答案

这可能完美。你看到什么是图片框控件后面。这是形式。谁的背景色是白色的可能。您可以设置窗体的BackgroundImage属性可以肯定,你应该通过图片中看到的图像。像这样的:

It probably works perfectly. You are seeing what's behind the picture box control. Which is the form. Whose BackColor is probably white. You can set the form's BackgroundImage property to be sure, you should see the image through the picture box. Like this:

通过冲压孔的两个的图片框的的形式,需要一个更大的武器,Form.TransparencyKey

Punching a hole through both the picture box and the form requires a bigger weapon, Form.TransparencyKey

这篇关于C#图片框透明的背景似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆