在picturebox的透明背景

在picturebox的透明背景

本文介绍了在picturebox的透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让图片框的背景透明。在图片框(矩形)中,我放置了一个图标(圆形)。我使图标透明,以便可以看到图标下方的其他药水。我尝试设置.backcolor = Transparent,但它不起作用。此外,在运行时使用.fromargb它不起作用。你对这个问题有什么解决方案吗?



提前谢谢

I want to make the background of a picturebox transparent. In the picturebox (rectangular shape), I placed an icons (circular in shape). I make the icon transparent so that other potion underneath the icon can be visible. I tried with setting the .backcolor = Transparent, but it doesn't work. Also during runtime with the .fromargb it doesn't work. Do you have any solution of this problem?

Thanks in advance

推荐答案



public class Test_PictureBox : System.Windows.Forms.PictureBox
{

    public Test_PictureBox()
    {
        this.Width = 100;
        this.Height = 100;

        SetTransparenz();
    }

    private void SetTransparenz()
    {
        this.SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
        this.SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, false);
        this.SetStyle(System.Windows.Forms.ControlStyles.ResizeRedraw, true);
    }

    protected override System.Windows.Forms.CreateParams CreateParams
    {
        get
        {
            System.Windows.Forms.CreateParams cp = base.CreateParams;
            cp.ExStyle = cp.ExStyle | 0x20;
            // Turn on WS_EX_TRANSPARENT
            return cp;
        }
    }

}


这篇关于在picturebox的透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:57