0

In our project I created a form and run it like below:

 Application.run(myform);

In this form we need draw something so its OnPaint method is overridden and there is no problem normally, however OnPaint is never called when we show a messagebox or form like:

 Messagebox.show("something");

or

 formA.showDialog();

So when users drag the messagebox, it will leave tracks because the background can't be repaint. Does any one know why and how to solve this problem?

Garfex
  • 111
  • 1
  • 4
  • Can you post the code from OnPaint. – Adrian Fâciu Aug 08 '12 at 07:03
  • You would not normally expect a paint message when another window covers yours, Windows(tm) will re-draw what was there when the other window moves. If on the other hand the underlying data that you are rendering in OnPaint changes whilst you are partly covered by the other window a call to invalidate would fix that – Adam Straughan Aug 08 '12 at 07:08
  • 2
    Could you post minimal code, that reproduces this behavior? – Dennis Aug 08 '12 at 07:10

1 Answers1

-1

You can make the form repaint by call the Refresh method.

var timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();

void timer_Tick(object sender, EventArgs e)
{
    Refresh();
}
Charlie
  • 1,292
  • 8
  • 7
  • 1
    I think this would be a bad idea for any solution. Here you are consuming a thread pool thread and doing nothing useful with it. If you really wanted this kind of refresh then better to create a basic timer on the UI thread or listen to the WM_IDLE message, there are many other solutions that don't include Sleep. On the plus side you did use Invoke – Adam Straughan Aug 08 '12 at 10:28