How do I force a repaint from a custom control?

  • Thread starter Thread starter Tom P.
  • Start date Start date
T

Tom P.

I am making a custom control (a ProgressBar) and was wondering how do
I force the control to paint like the base ProgressBar does? As it is
my control doesn't paint until the main execution loop let's it,
usually with Application.DoEvents. But even if I do an
Application.DoEvents() in my OnPaint it doesn't paint the control.
Thanks,

Tom P.
 
I am making a custom control (a ProgressBar) and was wondering how do
I force the control to paint like the base ProgressBar does? As it is
my control doesn't paint until the main execution loop let's it,
usually with Application.DoEvents. But even if I do an
Application.DoEvents() in my OnPaint it doesn't paint the control.

Don't call DoEvents().

Typically, your UI should be independent of your processing. The UI
should use the normal mechanisms for painting, which means it only draws
from within the OnPaint() method (or in a Paint event handler), and you
use Invalidate() to alert Windows that the UI needs to be redrawn.

Then you access the UI from your processing which, assuming that's going
on in a different thread, can be done using the Control.Invoke() or
Control.BeginInvoke() method.

Google Groups can help you find the numerous threads in this newsgroup
already discussing these techniques.

Pete
 
Back
Top