Click here to Skip to main content
15,896,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to open second form from first form in c# ?
Posted
Comments
Aniket Yadav 14-Mar-12 1:59am    
Is it MDI application?
Janardan Pandey 14-Mar-12 2:02am    
it is window application
Sergey Alexandrovich Kryukov 14-Mar-12 2:21am    
Not an answer. Please answer if it MDI or not (and better don't use MDI, who needs it?).
--SA
Janardan Pandey 14-Mar-12 4:39am    
It is an MDI application

There is a little trick in it, so many beginners get confused when reading a usual MSDN help page:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

The reason is: there is no such concept as "open a form", even though a form can be closed. You simply create a form with its constructor and later call the method Show or ShowDialog to show imitating modal dialog behavior. However, I strongly recommend to use the relationship owned form / owner form, so better keep the main form and owner of all other non-modal forms, use AddOwnedForm, please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx[^].

That's it.

And yes, better never use MDI, don't torture yourself and scare off your users with this ugly design style. If you have questions on it, I'll explain.

—SA
 
Share this answer
 
Hi,

Create a form in your Visual Studio and then specify name of your to be open form, i.e 'openedform'

Use code below at button click or whatever:
C#
openedform frm = new openedform();
frm.Show(); // or frm.ShowDialog() to open a form as dialog


Hope this help.
 
Share this answer
 
Hi,
when you create application it is provided with 1 from. Just Right click on the project and add new form.
then create a object for the Form2 in Form1 Class.
Form2 objForm2 = new Form2();
objform2.Show();


Further, if you want to change any thing in Form1 form Form2, better to send the current object of form1 to Form2, this way

Form2 objForm2 = new Form2(this);
objform2.Show();

create a copy constructor for the Form2.
 
Share this answer
 

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