Render winforms controls more smoothly

扶醉桌前 提交于 2019-12-29 08:12:20

问题


My winforms application is rendering very choppy. Is there a technique that can be used to either draw a form off screen, or to have it be hidden until the layout has been processed? Anything to help speed up the visual load of my forms.

Thanks for any help.

edit:

Forms have a couple grids each, and around 20 - 30 additional controls (textboxes / checkboxes). All controls are third party and I don't do any custom painting myself.


回答1:


You are getting perilously close to having too many controls on your form. You'll see each control taking its turn painting itself. Double buffering cannot fix this, the entire form with all control windows would have to be double-buffered. That's possible since XP, it supports the WS_EX_COMPOSITED window style flag. It won't speed up painting but the screen won't be updated until all rendering is completed.

Paste this code into your form to enable it:

protected override CreateParams CreateParams {
  get {
    CreateParams cp = base.CreateParams;
    cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
    return cp;
  }
} 



回答2:


You can to call SuspendLayout and, later, do a ResumeLayout.



来源:https://stackoverflow.com/questions/2255605/render-winforms-controls-more-smoothly

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