form is shown in background... should be foreground

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.
 
T

Terry

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
}
}
 
B

bbla32

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


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top