C#: Form.DoubleBuffered = true kills transparancy
- Create a new windows forms project
- Set TransparancyKey & BackColor of this form to "Black"
- 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
精彩评论