Form is shown transparent" />
开发者

C#: Form.DoubleBuffered = true kills transparancy

开发者 https://www.devze.com 2023-04-03 18:53 出处:网络
Create a new windows forms project Set TransparancyKey & BackColor of this form to \"Black\" Run => Form is shown transparent
  1. Create a new windows forms project
  2. Set TransparancyKey & BackColor of this form to "Black"
  3. Run

=> Form is shown transparent

Now also set the Form.DoubleBuffered property to true

=> Form 开发者_运维技巧isn't shown transparent anymore

Why this? Any workarounds for getting a double buffered transparent form?


You don't need to worry about your TransparencyKey and BackColor properties for transparency and double buffering to work. Leave them as default and try it again. Then, if you really want your backcolor to be black, try to apply that value.

The following snippet produces a 50% transparent window on my machine:

using System;
using System.Drawing;
using System.Windows.Forms;

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e) {
        DoubleBuffered = true;
        AllowTransparency = true;
        BackColor = Color.Black;
        Opacity = .5;
    }
}


I have just tried your steps to replicate and it is working fine for me. Perhaps this is a .Net version / OS version / Graphsics issue of some kind.

For reference I am testing with...

  • VS 2010
  • Windows 7 (32 bit)
  • .Net 4
0

精彩评论

暂无评论...
验证码 换一张
取 消