Using Invalidate

D

Dom

I have reason to call ListBox1.Invalidate, in order to capture the
DrawItem Event. There is a noticeable flickering in the ListBox that
I'd like to get rid of. By debugging, I can tell that Invalidate is
erasing the entire ListBox. I remember in the days of plain old "C",
that the InvalidateRect routine took a parameter that allowed you to
avoid this erasing. Is there a way to do this in CSharp?

Dom
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Dom said:
I have reason to call ListBox1.Invalidate, in order to capture the
DrawItem Event. There is a noticeable flickering in the ListBox that
I'd like to get rid of. By debugging, I can tell that Invalidate is
erasing the entire ListBox. I remember in the days of plain old "C",
that the InvalidateRect routine took a parameter that allowed you to
avoid this erasing. Is there a way to do this in CSharp?

There's an overload of the Invalidate method that takes a rectangle.
 
D

Dom

There's an overload of the Invalidate method that takes a rectangle.

Thanks, worked great. I still don't see why you can't just specify,
"don't erase before invalidation."

Dom

Dom
 
P

Peter Duniho

Dom said:
I have reason to call ListBox1.Invalidate, in order to capture the
DrawItem Event. There is a noticeable flickering in the ListBox that
I'd like to get rid of. By debugging, I can tell that Invalidate is
erasing the entire ListBox. I remember in the days of plain old "C",
that the InvalidateRect routine took a parameter that allowed you to
avoid this erasing. Is there a way to do this in CSharp?

In .NET, you control background erasing by overriding the
OnPaintBackground method. If you like, in that method you can simply do
nothing. Alternatively, you can set the AllPaintingInWmPaint control
style and you should not get background paint events at all
(WM_ERASEBKGND is ignored).

Of course, with either method you should of course make sure that the
OnPaint method always draws to the entire control.

I note in your follow-up that you say that invalidating a rect fixes the
problem. I'll point out that it doesn't really. It just makes it less
noticeable, because less of your control is redrawn (and thus less is
erased...everything happens faster, and to a smaller area). But there's
still flicker.

IMHO, unless you have specific needs for finer control of the drawing,
the best way to eliminate flicker is to simply set the Control's
DoubleBuffered property. This will cause all of the erasing and
redrawing to happen to an off-screen buffer, which is then copied all at
once to the on-screen representation of the Control. Doing that
eliminates the "erase then draw" sequence from what the user sees, thus
eliminating the flicker.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top