透明或半透明的面板控制 [英] Transparent or semitransparent panel control
问题描述
有没有什么办法,使面板透明或半透明?我还没有发现任何适当的属性设置为透明的面板。
Is there any way to make a panel transparent or semi transparent? I haven't found any appropriate property to set transparency for a panel.
我也试图与电网WPF控件(网格背景和控制的背景设置为透明),并将其放置在普通窗口的形式,但是当我把这个正常的Windows窗体(不是WPF)控制我没有得到正确的透明度。
I was also trying to make a WPF control with grid (grid background and control background was set to transparent) and place it on normal windows form, but when I put this control on normal Windows Form(not WPF) I don't get the proper transparency.
推荐答案
如果你的显示器是非常静态的,你可以做到这一点,实现半透明度(源):
If your display is pretty much static, you can do this to achieve semi-transparency (Source):
class SeeThroughPanel : Panel
{
public SeeThroughPanel()
{
}
protected override CreateParams CreateParams {
get {
var cp = base.CreateParams;
cp.ExStyle |= 0x00000020;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 0, 0, 0)), this.ClientRectangle);
}
}
不过,这种方法也不是没有问题,如果你需要在你的半透明控制动态渲染。请参见我已经张贴了这个问题。希望它有一天得到回答。
But, this approach is not without problems if you need dynamic rendering on your semi-transparent control. See this question which I have posted. Hope it gets answered someday.
这篇关于透明或半透明的面板控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!