Yesterday I found something very strange (I think). It looks like Form.TransparencyKey
gives different results based on which color is used as BackgroundColor
and TransparencyKey
. If you want to reproduce this, do following:
Panel
on the form BackgroundColor
and set Form1's TransparencyKey
also to Green Do you know why is that happening? What's the rule? I'm using .NET 4 with VS2010, tested on two computers with same configuration.
Not much code for this... But I can post settings in designer:
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(23, 26);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(229, 176);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.Red;
this.ResumeLayout(false);
}
//that outside:
private System.Windows.Forms.Panel panel1;
I've heard of this problem before but never realized it was related to the TransparencyKey choice. Nice find. It is almost certainly caused by Aero. With it disabled, the effect is implemented by use of a hardware overlay in the video adapter. With it enabled, the desktop window compositing feature implements it. You can typically tell by a very brief flash of the transparency color before DWM catches up and replaces the area with the pixels from the windows in the background. Turning DWM off for your window might fix the problem but you'll also lose the glass effects.
I can see little rhyme or reason to the color value, looks pretty random to me. Hard to call this anything else than a bug. I never ran into this before myself, I always use the same transparency key. Color.Fuchsia, an excellent fuchsed-up color. Recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With