Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 刷新后控件不再透明_C# - Fatal编程技术网

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窗体