Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
902 views
in Technique[技术] by (71.8m points)

.net - Render winforms controls more smoothly

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
  }
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...