1

Good day.

I am working on custom control (really it's Panel with gadgets) that contains some number of another controls. In this case, there are instances of MyEmbeddedControl : UserControl with few panels, buttons, labels and my methods. The behaviour of controls does not matter, point is they have certain locations within custom control. Problem is that CPU load increases up to 99% and crazy lags during scrolling my control:

Normal state enter image description here

During scrolling enter image description here

I tried set DoubleBuffered to true. There are many user controls, but showing area is small. I do not understand why paint is so hard. May be I am wrong and I'd better do not use many controls inside my custom control? What are the best practices?

Feofilakt
  • 1,341
  • 2
  • 13
  • 33
  • The default implementation for scrolling is to adjust the drawing origin and draw everything, letting the client boundary clip what isn't actually shown. You don't say how many child controls you have, but if it's a large number it's certainly possible you're reaching the limits of your computer to keep up. The solution is non-trivial, but does work: manage your own scrolling and only draw those child controls you know are visible in the window. – Peter Duniho Dec 02 '14 at 08:00
  • But it's standard controls, I only set Parent and Location, and they are drawn automatically. How can I draw them manually within the certain area? – Feofilakt Dec 02 '14 at 08:11
  • Because WinForms controls are mostly just thin wrappers around Windows native controls, it's (as I wrote) non-trivial. You'd have to intercept window messages and adjust the transform for the HDC before the control gets to draw. To go into enough detail to actually explain it is far more than a StackOverflow answer's worth of words. But that's the general idea. Of course, you could also re-implement the controls yourself as purely-managed objects; depending on the types of controls, that may or may not be an easier approach. – Peter Duniho Dec 02 '14 at 08:43
  • I could swear I saw @HansPassant explain this a couple of times every month, but I can't quite put my finger on it at. Maybe, if you mumble his name 3 times.. – TaW Dec 02 '14 at 16:19
  • Here you will Find some clue: ? – Aditya Rathore Aug 27 '19 at 05:56

0 Answers0