我为自己创建了一个透明面板。
public TransPanel()
{
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (ImageForBackGround != null)
{
e.Graphics.DrawImage(ImageForBackGround, new Point(0, 0));
}
}
它工作正常,但我有一个问题,如果我执行 .Refresh(); 控件不再透明 或 .Invalidate();。然后控件只有与他的父级相同的颜色。我已经尝试过覆盖 BackgroundOnPaint-Event,但它不起作用。
protected override void OnPaintBackground(PaintEventArgs pevent)
{
Application.DoEvents();
}
有人可以帮助我吗?提前致谢。