refresh flicker even w/ double buffering

K

kpg

Hi all,

New to CF 3.5 development, trying my hand at it.

I have a simple user control (VB), a gauge control, that displays a bitmap
background and I'm drawing a moving needle on top of it.

Works fine except for a flicker when the control is re-drawn.

I am using a bouble-buffering technique in the paint event as follows:

doubleBuffer = New Bitmap(Width, Height)
Dim g As Graphics = Graphics.FromImage(doubleBuffer)
g.DrawImage(backGroundImage, 0, 0)
g.DrawLine(New Pen(mycolor, 2), X1, Y1, X2, Y2)
g.Dispose()
e.Graphics.DrawImage(doubleBuffer, 0, 0)

The control is updated between 4 to 10 time/second, and this causes a
flicker. I'm sure without double buffering it would be much worse, but it
is still unacceptable.

During the e.graphics DrawImage it seems to first clear the old image then
re-paint the new image, which causes a noticeable flicker. This seems to
defeat the whole purpose of double buffering.

I'm not very familiar with .NET graphics, and while I do understand that
the CF has a much limited capability, there must be a way to achieve
flicker free animation at these frame rates.

Thanks,

kpg

PS

I have yet to try this, but I was considering putting a background on the
form instead of the user control, then have a transparent color in the
control background bitmap (using setcolor), which then would have only the
needle drawn on it. I'm assuming here that the transparent color is simply
not rendered, but I'm uncertain if the needle I then draw would remain on
each frame cycle, requiring a refresh of the underlying image. I am
thinking that any "image persistence" capability is not present in CF?

PPS

....oh, BTW - I have a functional CF DrawArc routine. It was created out of
necessity (I could not find source code for this anywhere) and with some
help from a blog by Dan VanderBoom. It's not real pretty but it does work
well and its small and fast enough. I'm using if for arcs based on
circles, but I think it should work for any ellipses as well. If anyone is
interested I'll post it to a new thread.
 
K

kpg

You probably need to override OnPaintBackground and have it do nothing.


You mean for the form or the user control?

In either case my form and/or control do not seem to have a
OnPaintBackground event. All I have is a paint event.

Is this becuase I'm using VB?

If so, I'll gladly switch over to C# for this control...
 
C

Chris Tacke, MVP

Just like you should be doing for Paint, override the method (in the
control). It's not an event. Handling this in an event is going to be
slower by nature I think.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
K

kpg

Just like you should be doing for Paint, override the method (in the
control). It's not an event. Handling this in an event is going to be
slower by nature I think.

Got it. I was thinking OnPaintBackground was an event, sounds like an
event.

Anyway this works perfectly - no flicker at all.

Thanks,
kpg
 
C

Christopher Fairbairn [MVP]

Hi,

kpg said:
"Chris Tacke, MVP" <ctacke.at.opennetcf.dot.com> wrote in (e-mail address removed):
Got it. I was thinking OnPaintBackground was an event, sounds like an
event.

Most Microsoft APIs follow the advice outlined in their "Design Guidelines
for Class Library Developer" documentation (available at
http://msdn.microsoft.com/en-us/library/ms229042.aspx).

In particular there is a section within this document discussing recommended
best practices for exposing Events from a custom class -
http://msdn.microsoft.com/en-us/library/ms229011.aspx

The general design pattern Microsoft uses is for an event called "Paint" to
have an associated virtual method called "OnPaint". This allows subclasses
to override the method instead of needing to add an event handler. This
provides a bit more efficiency and flexability in what a subclass can do
over an ordinary event handler.

The inverse is not always true however, in the case of the background
painting mechanism there is an OnPaintBackground virtual method, but no
matching "PaintBackground" event.

Its uncommon to find an event that starts with the word "On", but that is
not to say there aren't classes out there like that...

Hope this helps,
Christopher Fairbairn
 

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