Reputation: 49544
I'm building a custom control that has its own set of headers.
The headers (another custom control) exist as a child control of the aforementioned custom control.
When I resize the headers (part of the child control), the child contol is calling Invalidate() on itself, which should queue a message to repaint.
After the child contol has been invalidated, the parent control is notified that the header has resized, and it issues its own Invalidate() command.
This is shown by this trace:
Headers.Invalidate()
List.Invalidate()
Headers.Invalidate()
List.Invalidate()
However, when it comes time to start repainting, the parent control receives its Paint event first, followed by the header control:
List.Paint
Headers.Paint
When I move the mouse rapidly, the mouse move events appear to be queued in front of the paint events, so the invalidates continue to be called, but the parent control's paint events always fire first:
List.Paint
List.Paint
List.Paint
List.Paint
Headers.Paint
List.Paint
List.Paint
Headers.Paint
This causes the header control to lag behind the list substantially. Ideally, both paint events would fire together, and all mouse move events would queue before the paint events (so that the painting is always in sync, but the mouse events are all flushed out in between paints.)
I have no idea where to start on fixing this issue.
Where do I start, to fix the lag that my header experiences?
Upvotes: 0
Views: 1148
Reputation: 49544
The answer is to make the redrawing synchronous by manually drawing, using the Update
or Refresh
methods.
The Update
method will simply repaint the controls and all children synchronously.
The Refresh
method will invalidate the control and all children, then will call Update
.
Upvotes: 1
Reputation: 154
are you already using double buffering? It might be slower, but it should synchronize the repaints so that both appear to update when an update happens.
You can switch on double buffering in a Form with:
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
Also, you might want to try:
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, false);
Upvotes: 0