Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How can I run form inside another?
This is my code, the problem in it is the second form run before the first one
C#
private void Form1_Load(object sender, EventArgs e)
        {
            form2 f = new form2();
            f.ShowDialog();}
Posted

1 solution

Try the Show method instead:
C#
form2 f = new form2();
f.Show();}

The ShowDialog method halts all processing until teh new form is closed, the second doesn't - it returns immediately.
 
Share this answer
 
Comments
Thomas Daniels 27-Oct-12 12:32pm    
Good answer, +5!
Member 8584763 27-Oct-12 14:00pm    
Still the second one runs before the first one.
OriginalGriff 27-Oct-12 14:06pm    
Do you mean you want the first form fully displayed before you even start to show the second?
If so, then try moving the code into the first form Shown event instead of the Load event - it is signalled when the for is actually displayed, rather than loaded.
If yopu have some other problem, then try explaining in more detail - remember we can't see your screen, just what you tell us.
Member 8584763 27-Oct-12 14:11pm    
Thanks ,it worked. Is it possible the second form to be displayed in the first form like mdiparent?
OriginalGriff 27-Oct-12 14:15pm    
Ye---es...

But unless the first form is a MDI parent, it's a bit of a pain, and rarely looks good.

Instead, I would make the second form a Usercontrol, and display that inside the first form. If you need it as an independent form as well, you can embed the control in a form and hide the original version.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900