问题描述
我不知道如何改变或修改面板的透明度,在C#中,而不是整个表格,但小组唯一的。我已经看到了很多的不透明度C#教程,但它的形式。即时寻找它怎么可能只用面板是可能的。谢谢!
I was wondering how to change or modify the transparency of a Panel in C#, not the whole form, but the panel only.. I've seen many C# tutorials on Opacity, but its for the Form. im looking for how it could be possible with the Panel only. Thank You!
推荐答案
是的,不透明度只能工作在顶级窗口。它使用了视频适配器,在不支持的子窗口,象面板的硬件特征。 Winforms中唯一的最高级别控制派生类的形式。
Yes, opacity can only work on top-level windows. It uses a hardware feature of the video adapter, that doesn't support child windows, like Panel. The only top-level Control derived class in Winforms is Form.
几个纯WinForm的控制,那些做让本机Windows控制自己的绘画,而不是做的工作,但不支持透明背景色。小组就是其中之一。它使用了一招,它要求家长自行绘制来产生背景像素。这一招的一个副作用是,重叠控件不工作,你只看到了父母的像素,而不是重叠的控制。
Several of the 'pure' Winform controls, the ones that do their own painting instead of letting a native Windows control do the job, do however support a transparent BackColor. Panel is one of them. It uses a trick, it asks the Parent to draw itself to produce the background pixels. One side-effect of this trick is that overlapping controls doesn't work, you only see the parent pixels, not the overlapped controls.
这样表显示了它的工作:
This sample form shows it at work:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.BackColor = Color.White;
panel1.BackColor = Color.FromArgb(25, Color.Black);
}
protected override void OnPaint(PaintEventArgs e) {
e.Graphics.DrawLine(Pens.Yellow, 0, 0, 100, 100);
}
}
如果这还不够好,那么你需要考虑彼此顶部堆叠形式。 Like这。
If that's not good enough then you need to consider stacking forms on top of each other. Like this.
值得注意或许是,这个限制被提升在Windows 8.不再使用视频适配器叠加功能和DWM(又名航空)不能再被关闭。这使得不透明/透明的子窗口容易实现。就凭这当然是未来的音乐一会儿就来。 Windows 7将成为下一个XP:)
Notable perhaps is that this restriction is lifted in Windows 8. It no longer uses the video adapter overlay feature and DWM (aka Aero) cannot be turned off anymore. Which makes opacity/transparency on child windows easy to implement. Relying on this is of course future-music for a while to come. Windows 7 will be the next XP :)
这篇关于我怎样才能设置的WinForms面板的不透明度和透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!