Flicker free TextBox

2019-06-23 18:28发布

I have a simple Winforms multiline TextBox on my Form. Whenever I resize or move the TextBox its content starts to flicker madly. That looks very disgusting and might even cause epileptic seizure for some users ;-)

Is there a way to manipulate the redrawing process of the TextBox to get rid of the flickering?

2条回答
倾城 Initia
2楼-- · 2019-06-23 19:07

I've found a working solution on the MSDN forums written by Hans Passant. The following code can be added to the form and will work for all child controls, too:

    protected override CreateParams CreateParams {
        get {
            const int WS_EX_COMPOSITED = 0x02000000;
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= WS_EX_COMPOSITED;
            return cp;
        }
    } 
查看更多
小情绪 Triste *
3楼-- · 2019-06-23 19:07

afaik you can't control the resize mode of single controls on a form... in my opinion you have 2 options:

  1. find out why the flickering occurs - graphics driver issues?
  2. set the ResizeRedraw property of the form to false

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.resizeredraw.aspx

查看更多
登录 后发表回答