VS 2010 [RESOLVED] Flickering in user control but NOT with similar code painting a WinForms panel

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Flickering in user control but NOT with similar code painting a WinForms panel

I have been successfully drawing 6 analog gauges, each in their own panel on a form, by handling the panel's paint event. They look fantastic and have no flicker. I am updating them every 100 milliseconds. I tried to improve on this by creating a user control with a panel in it and adding some properties so that I could more easily create these analog gauges and use them in several projects. I am again handling the panels' paint event to draw the gauge. However, when I create 6 of these custom gauge controls and add them to a form, they flicker horribly. I have tried double-buffering which did not help or made it worse. Is there something fundamentally different about the way a user control works that is causing the flickering? I may just try to create a new class that inherits from panel and add my custom properties to it.

Re: Flickering in user control but NOT with similar code painting a WinForms panel

Originally Posted by tigerWereWolfMonkey

I have tried double-buffering which did not help or made it worse. Is there something fundamentally different about the way a user control works that is causing the flickering? I may just try to create a new class that inherits from panel and add my custom properties to it.

Try a picbox instead of a panel, IIRC a picbox is buffered by default, but if you need to use a panel try making a class for it, and set DoubleBuffered in the constructor,..

Re: Flickering in user control but NOT with similar code painting a WinForms panel

Edgemeal, You were spot on. Using a picture box instead of a panel worked. Also, I was mistaken about using a panel in my project. What I had working before I created the user control WAS using a picture box (inside a panel) and not a simple panel. (Which is why it was working so nicely). I need sleep!

Re: Flickering in user control but NOT with similar code painting a WinForms panel

Originally Posted by tigerWereWolfMonkey

Thanks for the response. Can you explain why it would not be flickering in a simple panel in my project but flickering in the panel in the custom user control?

There's no reason the user control should flicker, unless you do not have double buffering enabled. Painting to a panel, of course, potentially cause flickering. A user control would be a good candidate for a control which is used repeatedly, encapsulating all the code necessary to draw the control.

You also would not need to put any container on the control: just use the paint event of the control itself (no picture box, panel, etc.)

"Ok, my response to that is pending a Google search" - Bucky Katt."There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk."Before you can 'think outside the box' you need to understand where the box is."