form is shown in background... should be foreground

  • Thread starter Thread starter bbla32
  • Start date Start date
B

bbla32

A really weird problem:

Form1 is the main form. Clicking on its button displays:

Form2 as a modal form (ShowDialog). Clicking on its button has the
purpose to close this form and display Form3. The problem is that
Form3 is in the background. It is enough to change showing Form2 from
ShowDialog to Show and the issue disappears.

I've tested various methods, including FormWindowState, BringToFront
as well as WinAPI: SetWindowPos, SetForegroundWindow... Nothing helps!
Form3 is still in the background.
 
A really weird problem:

Form1 is the main form. Clicking on its button displays:

Form2 as a modal form (ShowDialog). Clicking on its button has the
purpose to close this form and display Form3. The problem is that
Form3 is in the background. It is enough to change showing Form2 from
ShowDialog to Show and the issue disappears.

I've tested various methods, including FormWindowState, BringToFront
as well as WinAPI: SetWindowPos, SetForegroundWindow... Nothing helps!
Form3 is still in the background.

You would be better showing Form3 from Form1 than Form2, i.e.:

public partial class Form1 : Form
{
private void ShowForm2()
{
Form2 form2 = new Form2();
form2.ShowDialog(this); // doesn't return until form is closed

// Form2 has closed so open Form3
Form3 form3 = new Form3();
form3.Show(this); // returns immediatly
}
}
 
You would be better showing Form3 from Form1 than Form2, i.e.:


True, but the point is to open Form3 from within Form2 class.
 
Back
Top