Question Layered graphics vs. flickering ?

cbreemer

Well-known member
Joined
Dec 1, 2021
Messages
188
Programming Experience
10+
I was having fun with programming an analog clock, but one thing I can't work out is how to avoid flickering. When e.g. the second hand moves forward one second, I first need to erase the previous position of the second hand before drawing the new position. I had that programmed nicely, but found it not working well after I set graphics.SmoothingMode = SmoothingMode.AntiAlias , random outline pixels would remain on the screen. To get rid of these I resorted to erasing a rectangle around the hand, rather than the hand itself.
An added complication is that, as with an old-fashioned clock, the second and minute hands extend right over the digits and the rim of the clock (see image) so every second I need to repaint the entire clock face as well in order not to see it gradually destroyed. All this repainting inevitably causes the occasional flickering. Setting the form's DoubleBuffered property did not seem to help. Note that I'm drawing directly onto the graphics object of a Panel, I don't use a Paint event handler.
Maybe it's wishful thinking but I have a feeling that instead of all this wiping and repainting there must be a more clever solution to this, such as using layers or a non-destructive drawing mode, but I haven't been able to find it. Any ideas would be appreciated.
c.jpg
 
Setting the form's DoubleBufferedproperty did not seem to help. Note that I'm drawing directly onto the graphics object of a Panel, I don't use a Paint event handler.
The double buffering only works with paint events. Drawing directly to the DC won't be buffered.
 

Latest posts

Back
Top Bottom