C#Form.TransparencyKey工作不同的颜色不同,为什么?不同、颜色、工作、Form

由网友(国民坏叔叔)分享简介:昨天,我发现了一些很奇怪(我认为)。它看起来像 Form.TransparencyKey 给出了基于不同的结果上的颜色作为 BackgroundColor中和 TransparencyKey 。如果你想重现此,执行以下操作:创建新的Windows窗体应用程序删除一个面板的形式在给它的绿色为 BackgroundCo...

昨天,我发现了一些很奇怪(我认为)。它看起来像 Form.TransparencyKey 给出了基于不同的结果上的颜色作为 BackgroundColor中 TransparencyKey 。如果你想重现此,执行以下操作:

创建新的Windows窗体应用程序 删除一个面板的形式 在给它的绿色为 BackgroundColor中,并设置Form1的 TransparencyKey 还绿 运行程序,并把表格和洞过的东西,你会看到,你可以通过该孔点击(如由MSDN) 现在,同时改变颜色,红,运行应用程序 - 你可以看到一个洞,但不再可以点击尽管它

你知道这是为什么发生?什么是规则?我使用的是.NET 4 VS2010,在两台计算机上具有相同配置的测试。

没有太多code这个...但我可以在设计师的发布设置:

 私人无效的Ini​​tializeComponent()
{
     this.panel1 =新System.Windows.Forms.Panel();
     this.SuspendLayout();
     //
     // PANEL1
     //
     this.panel1.BackColor = System.Drawing.Color.Red;
     this.panel1.Location =新System.Drawing.Point(23,26);
     this.panel1.Name =PANEL1;
     this.panel1.Size =新System.Drawing.Size(229,176);
     this.panel1.TabIndex = 0;
     //
     // Form1中
     //
     this.AutoScaleDimensions =新System.Drawing.SizeF(6F,13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize =新System.Drawing.Size(284,262);
     this.Controls.Add(this.panel1);
     this.Name =Form1的;
     this.Text =Form1的;
     this.TransparencyKey = System.Drawing.Color.Red;
     this.ResumeLayout(假);
}
//那之外:
私人System.Windows.Forms.Panel PANEL1;
 

解决方案

我听说过这个问题,但从来没有意识到这是关系到TransparencyKey选择。尼斯找到。它几乎可以肯定是由航空造成的。有了它禁用,效果是通过利用在所述视频适配器硬件重叠的实现。有了它启用后,桌面窗口合成功能,实现它。通常可以由透明颜色的非常简短的闪光告诉之前DWM赶上和替换从窗户在背景中的像素的区域。打开DWM关闭你的窗口可能会解决这个问题,但你也失去了玻璃特效。

我看不出有什么没头没脑的颜色值,看起来pretty的随机给我。很难称之为别的不是一个错误。我从来没有碰到了这个自己之前,我总是使用相同的透明度关键。 Color.Fuchsia,一个优秀的fuchsed向上的颜色。推荐使用。

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:

Create new Windows Forms application Drop a Panel on the form Give it "Green" as BackgroundColor and set Form1's TransparencyKey also to Green Run program and put Form with "hole" over something and you'll see that you can click through that hole (as described by MSDN) Now change both colors to "Red" and run application - you'll see the "hole" but you no longer can click though it 怎么让Excel用不同颜色显示不同类型的数据

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.

阅读全文

相关推荐

最新文章