Reduce flickering By Turning off WS_CLIPCHILDREN

风格不统一 提交于 2019-12-11 10:50:05

问题


I have developed a windows application whose interface has a multiple text boxes and all of them are placed in one panel (the panel have a background image).

Whenever the panel is being loaded, the window(with these textboxes) is flickering.

I read a lot of suggestions to minimize this flickering, One of the suggested solutions was the following,

SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
SetStyle(ControlStyles.DoubleBuffer, true);

But it does not work with me,

I read about turning off the WS_CLIPCHILDREN using this code:

protected override CreateParams CreateParams {
  get {
    var parms = base.CreateParams;
    parms.Style &= ~0x02000000;  // Turn off WS_CLIPCHILDREN
    return parms;
  }
}

This code help some people who faced the same problem. So I want to use it but I really don't know where to paste it, I mean, I read that it should be pasted not in the form, but in the the UserControl's code. I don't know how to do that, all the controls that i used is not a custom controls.

Take a look here & see the 1st answer:

How to fix the flickering in User controls

Thanks in advance,


回答1:


You might consider turning on WS_EX_COMPOSITED style also, it may help in some cases:

parms.ExStyle |= 0x02000000; //WS_EX_COMPOSITED



回答2:


Try deriving from Panel and setting DoubleBuffered() to True:

public class BufferedPanel : Panel
{
    public BufferedPanel()
    {
        this.DoubleBuffered = true;
    }
}

Then use that from your ToolBox instead of the default Panel.



来源:https://stackoverflow.com/questions/16376567/reduce-flickering-by-turning-off-ws-clipchildren

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!