Repaint order of invalidated child controls

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I'm developing a hex editor control, and it displays the hex and raw views into the document using a number of subcontrols. This is great, but now I'm seeing a bug when I scroll my control very fast.

How it should look:
http://www.omega-prime.co.uk/files/invalidate-desired.png

How it does look:
http://www.omega-prime.co.uk/files/invalidate-bug.png

Since scrolling the control forces all the subcontrols to invalidate, and they repaint separately, it can occur that they get out of sync on screen (in this case, the selection is clearly different for each control). This, however, would be OK if I could just get Windows to redraw the least recently repainted control first (the flicker would become unnoticable).

The problem is that this doesn't seem to be possible. The order in which I issue Control.Invalidate calls is irrelevant! For example:

INVALIDATE TextAdapter
INVALIDATE SeparatorAdapter
INVALIDATE HexAdapter
INVALIDATE SeparatorAdapter
INVALIDATE AddressAdapter
PAINT AddressAdapter
PAINT SeparatorAdapter
PAINT HexAdapter
PAINT SeparatorAdapter
PAINT TextAdapter

This can lead to situations like this (when scrolling fast):

INVALIDATE AddressAdapter // Scrolled for the first time, invalidate everything
INVALIDATE SeparatorAdapter
INVALIDATE HexAdapter
INVALIDATE SeparatorAdapter
INVALIDATE TextAdapter
PAINT AddressAdapter // Windows starts to paint...
INVALIDATE AddressAdapter // Scrolled again, only invalidate what needs redrawing in a vain hope that repaints work as a queue
PAINT AddressAdapter // Windows starts to paint again, but not as a queue, so e.g. AddressAdapter is always redrawn with top priority, leading to the bug
PAINT SeparatorAdapter
PAINT HexAdapter
PAINT SeparatorAdapter
PAINT TextAdapter

So, is there a clean way to make invalidate events occur in order? Or is there a better way to handle this graphical bug?

Thanks in advance!

Max
.



Relevant Pages

  • Re: Graphics ... almost working ... missing one line?
    ... The flicker is because calling Invalidate() causes the entire control to be erased first, before the OnPaintmethod is called. ... You can avoid this in a couple of ways, but the simplest in a custom control is to just set the DoubleBuffered property of your control to true (note that this property has nothing to do with your own buffering...it causes the OS to create a new off-screen buffer to be used for drawing during updates to the control). ... Trying to update any more frequently than that is likely to lead to uneven animation, with some frames being displayed much shorter or longer periods of time than others. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to give parameters to the paint event handler
    ... screen or control or control portion is repainted. ... will know when to paint itself and will then paint the dot. ... If you just call invalidate() then that means all of it. ... >> Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Graphics ... almost working ... missing one line?
    ... Even after you ran into problems with the wrong design, admitted it was because of the wrong design, and were provided additional details on how to do it right, you insisted on doing it wrong. ... where does your drawing code go? ... let the control itself deal with a variety of display issues. ... invalidate the control in reaction to changes to data. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: user controls in compact framework 3.5
    ... If that in turn forces a change in a property, ... inherits from Control class. ... Then I override OnPaint method. ... Is it a good idea to call Invalidate methos there? ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How to get ListBox to show changes made to an item in C#?
    ... each time you add/remove an item an Invalidate() is sent to the ... update redraw the invalidated part of the control, ... a listbox gets an object collection, ...
    (microsoft.public.dotnet.languages.csharp)