0

The scenario is, I have a Scrollbox which is a container control for several custom controls which I create at runtime. The custom controls are movable and resizeable.

Typically the custom controls contain charts populated with data, some of the charts contain quite a lot of data so repainting them is quite expensive time wise.

The enclosing custom control is the vehicle which allows the charts to be moved around the scrollbox and the one that is moved never gets a paint message.

However if the control moves over another control, then that control gets a paint message which stutters the movement and creates "trails" (which clear themselves once movement is finished);

The question is, why are these controls getting paint messages in the first place if nothing has changed in them to warrant a repaint?

Why does it not just use the double buffered bitmap like the one that is being moved?

Andy k
  • 1,056
  • 1
  • 11
  • 22
  • Something is changed. They were partially covered before, and which part that is (and so which part needs painting) changes when the control moves over them. – GolezTrol Feb 19 '19 at 11:13
  • 2
    And doublebuffered can improve the painting experience if there is a lot of drawing of elements over one another. It will look better if everything is drawn at once on the control. It _may_ go a bit faster as well, but that's not the main goal, and doublebuffered doesn't mean there is no painting. It's painted on the buffer, after which the buffer is painted on the control. There is no 'caching' of what was painted, unless you implement that yourself. – GolezTrol Feb 19 '19 at 11:16
  • @GolezTrol if the screen objects are forms then no repainting happens when one form moves over another. It must be using a cache. The only time a control needs to repaint is when the user changes the content or it gets resized. – Andy k Feb 19 '19 at 12:08
  • 3
    Forms are a special case, and the OS helps in caching them (to be able to drag forms, even when their main thread is busy). – GolezTrol Feb 19 '19 at 13:06
  • 2
    @Golez is right, [DWM](https://learn.microsoft.com/en-us/windows/desktop/dwm/dwm-overview) takes care of top-level windows. As soon as any part of the update region of a child window is invalidated, it's notified to paint. – Sertac Akyuz Feb 19 '19 at 13:55
  • "*How to reduce ...*" might benefit from a test case to play on... – Sertac Akyuz Feb 19 '19 at 13:57
  • I'm not sure a question this general would benefit from a test case. I half suspected this was the case and there was no way around it. I just wanted to confirm it before I started to implement internal caches in my custom controls. Most of them draw to bitmaps first anyway. – Andy k Feb 19 '19 at 14:58
  • Yeah, probably it wouldn't.. Unless something somehow messes up with something.., like a missing WS_CLIPSIBLINGS etc.. – Sertac Akyuz Feb 19 '19 at 17:35

0 Answers0