OnPaint is not called when messagebox is shown

406 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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();
}