Transparent background on winforms?

前端 未结 9 1987
走了就别回头了
走了就别回头了 2020-11-29 03:39

I wanted to make my windows form transparent so removed the borders, controls and everything leaving only the forms box, then I tried to the BackColor and TransparencyKey to

相关标签:
9条回答
  • 2020-11-29 04:36

    The manner I have used before is to use a wild color (a color no one in their right mind would use) for the BackColor and then set the transparency key to that.

    this.BackColor = Color.LimeGreen;
    this.TransparencyKey = Color.LimeGreen;
    
    0 讨论(0)
  • 2020-11-29 04:36

    A simple solution to get a transparent background in a windows form is to overwrite the OnPaintBackground method like this:

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        //empty implementation
    }
    

    (Notice that the base.OnpaintBackground(e) is removed from the function)

    0 讨论(0)
  • 2020-11-29 04:40

    My solution was extremely close to Joel's (Not Etherton, just plain Joel):

    public partial class WaitingDialog : Form
    {
        public WaitingDialog()
        {
            InitializeComponent();
    
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
            this.TransparencyKey = Color.Transparent; // I had to add this to get it to work.
    
            // Other stuff
        }
    
        protected override void OnPaintBackground(PaintEventArgs e) { /* Ignore */ }
    }
    
    0 讨论(0)
提交回复
热议问题