为什么我的WinForm控件在paint事件之前闪烁? [英] Why do my WinForm controls flicker before the paint event?

查看:716
本文介绍了为什么我的WinForm控件在paint事件之前闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我在其中加载包含在里面3其他用户控件用户控件一个WinForm。
我每次都进入到一个诺特尔选项卡,并返回到用户控制3控制里面闪烁甚至befor任何事件触发。

I have a winform in which I load a user control that contains 3 other user controls in it. Every time I move to a nother tab and return to that user control the 3 controls inside it flickers even befor any event fires.

我试过每一件事情,包括

I tried every thing including:

        this.DoubleBuffered = true;
        this.SetStyle(ControlStyles.DoubleBuffer, true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.UserPaint, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams baseParams = base.CreateParams;
            baseParams.ExStyle |= 0x0200000;
            return baseParams;
        }
    }

protected override CreateParams CreateParams
    {
        get
        {
            CreateParams baseParams = base.CreateParams;
            baseParams.ExStyle &= 0x0200000;
            return baseParams;
        }
    }



但没有什么帮助......闪烁的发生befor任何代码运行...
可以是什么问题?

But nothing helps...The flickering happens befor any code runs... What can be the problem ???

推荐答案

这可能会发生,因为背景是正在绘制每一次。

This might be happening because the background is being painted every time.

如果的所有的你的画在的OnPaint做() (包括清除背景 - 这您的嵌套的用户控件可能做自己,所以这应该是确定),那么你就可以完全禁用背景画如下:

If all your painting is done in OnPaint() (including clearing the background - which your nested user controls are probably doing themselves, so that should be ok), then you can completely disable the background painting as follows:

protected override void OnPaintBackground(PaintEventArgs pevent)
{
    // Do nothing to disable background painting.
}

您可能会发现,你也需要做,在一个执行或您更多的嵌套的用户控件。

You might find that you need to also do that in the implementation of one or more of your nested user controls.

另外,如果您自定义现有的Windows控制,以防止闪烁,你有时必须做以下(但这不是你应该为你的用户控件之一)做的:

Also, if you are customising an existing Windows control to prevent it from flickering, you sometimes have to do the following (but this is NOT something you should do for one of your user controls):

private const int WM_ERASEBKGND = 20;

[PermissionSet(SecurityAction.Demand, Unrestricted=true)]

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_ERASEBKGND)
    {
        m.Result = IntPtr.Zero;
    }
    else
    {
        base.WndProc(ref m);
    }
}



我不得不做定制<$ c当$ C>的ListView 来防止它闪烁。

这篇关于为什么我的WinForm控件在paint事件之前闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆