I have main form.I invoke form2 from Mainform using form2.ShowDialog(Application.OpenForms["MainForm"]);
then i invoke another form from form2
this.Hide();
form3.ShowDialog(Application.OpenForms["MainForm"]);
this.Dispose();
Everything works fine but when a form3 is displayed i get a glimpse of any window displayed in the background ie:If i had opened MS paint put it in the background the Paint window will come on top of my window for time less than a second and automatically go to the backgroud.
Why is this behavior.How can i correct it?
When you call
this.Hide(), Form2 is hidden and another window needs to get focused. However, you opened Form2 with ShowDialog, which means Form2 is the only window that can get focused in your application. But since you hid Form2, Windows finds another window to focus (in this case MS Paint).One suggestion for a solution could be to artificially give MainForm focus before hiding Form2:
Perhaps a more beautiful solution would be to first open Form3, wait for it to be shown, and then hide Form2. To do this, put this code in Form2, when you want to show Form3: