C# transparent background for window form

前端 未结 4 1342
野趣味
野趣味 2021-01-12 15:40

I\'ve already seen Transparent background on winforms?

it doesnt offer solution to my problem. I am using the same method to try to achieve transparency



        
相关标签:
4条回答
  • 2021-01-12 16:20

    The way I did it long time ago was to find an unused color for the form background and then set the transparency key to it:

    this.BackColor = Color.Magenta;
    this.TransparencyKey = Color.Magenta;
    

    Other ways are:

    • Creating a background image, painting the transparent area of it with a specific color and setting it as the form BackgroundImage... then setting the TransparencyKey to that color.
    • Overriding OnPaintBackground method with an empty method.

    [EDIT] As Mario states, normally the default transparent color for the key is Magenta.

    0 讨论(0)
  • 2021-01-12 16:20
    public partial class TransprtScrcn : Form
        {
            public TransprtScrcn()
            {
                InitializeComponent();
                this.BackColor = Color.Red;
                this.TransparencyKey = Color.Red;
            }
    
    
            protected override void OnPaintBackground(PaintEventArgs e)
            {
                e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-12 16:34

    This is the best way to make the transparent background of winform.

    right after this:

    public partial class frmTransparentBackcolor : Form
    {
        public frmTransparentBackcolor()
        {
            InitializeComponent();
            //set the backcolor and transparencykey on same color.
            this.BackColor = Color.LimeGreen;
            this.TransparencyKey = Color.LimeGreen;
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(Brushes.LimeGreen, e.ClipRectangle);
        }
    }
    

    hope this will help.

    0 讨论(0)
  • 2021-01-12 16:40

    You can use a picture for this work. The color of bound of picture is Red , Next use this code

    this.TransparencyKey = Color.Red;
    
    0 讨论(0)
提交回复
热议问题