C# 刷新后控件不再透明
我为自己创建了一个透明的面板C# 刷新后控件不再透明,c#,C#,我为自己创建了一个透明的面板 public TransPanel() { } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; return cp; } } protected override void OnPaint(Pain
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(),控件将不再透明;或者a.Invalidate();。然后,控件的颜色与其父控件的颜色相同。
我已经尝试覆盖BackgroundOnPaint事件,但它不起作用
protected override void OnPaintBackground(PaintEventArgs pevent)
{
Application.DoEvents();
}
有人能帮我吗?提前谢谢。我现在找到了解决办法。只需将“不透明”设置为true
protected override void OnPaint(PaintEventArgs e)
{
if (ImageForBackGround != null)
{
e.Graphics.DrawImage(ImageForBackGround, new Point(0, 0));
this.SetStyle(ControlStyles.Opaque, true);
}
}
忘了说:我正在使用Windows窗体