提问人:TheFrieber_ 提问时间:10/7/2023 最后编辑:Matt Johnson-PintTheFrieber_ 更新时间:10/7/2023 访问量:42
在透明键控窗体上创建透明面板
Creating a Transparent Panel on a Transparent Keyed Form
问:
寻找解决方案,使面板在透明键控表单上透明。我使用的是“半透明”,但它只是采用表单的颜色,而不是真正透明的。不使用透明度:使用 5% 的不透明度
目前只使用“ExtendedPanel”,从帖子: https://stackoverflow.com/a/32402532/14788245
public class ExtendedPanel : Panel
{
private const int WS_EX_TRANSPARENT = 0x20;
public ExtendedPanel()
{
SetStyle(ControlStyles.Opaque, true);
}
private int opacity = 50;
[DefaultValue(50)]
public int Opacity
{
get
{
return this.opacity;
}
set
{
if (value < 0 || value > 100)
throw new ArgumentException("value must be between 0 and 100");
this.opacity = value;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
using (var brush = new SolidBrush(Color.FromArgb(this.opacity * 255 / 100, this.BackColor)))
{
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
base.OnPaint(e);
}
}
答: 暂无答案
评论