简体   繁体   中英

New form disappear after creation

I'm facing a problem with form show. I have a main form where I have my GUI and I choose an option that creates an instance of a form. For example in my main form I have:

Form2 f2 = new Form2();
f2.Show();

The problem is that the form shows for about 1-2 secs and then goes behind the main form.

I tried some instructions in the main form below f2.Show() command like

f2.BringtoFront();
this.SendtoBack();

Also I added commands to the new form ( Form2 ) load method:

this.BringtoFront();
this.Activate();
this.Focus();

Nothing of the above commands seems to be a solution for this. Only when I use f2.ShowDialog(); instruction in my main form but I don't want to do that because I need immediate access to both of these forms at the same time.

Any help? Thanks

If you don't want your second form to never go behind your main form then pass the owner in the overload of Show method that accepts the owner parameter

 Form2 f2 = new Form2();
 f2.Show(this);   // Assuming this code runs inside the main form

If you remove or change it to comment this.SendtoBack(); :

f2.BringtoFront();
//this.SendtoBack();

it'll be OK!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM