Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loading 2 forms

Status
Not open for further replies.

rohman

Programmer
Nov 2, 2003
10
US
I want 2 forms to load on screen and be seen right when the program loads. So far I am unable to do that. Any suggestions? How would I do that in C#?

I tried inserting Application.Run(new Form2()); in the Form1_load(). Got an error.

 
on form1 constructor...

public Form1()
{
Form frm = new Form();
frm.Show();
}
 
DO I have to make a Form 2 before I do that? And if I don't, will I be able to edit frm?
 
Im am not sure about how the 2 forms interact but the following code will show you two forms.
There are other ways to do depending on the application business.
Form1.cs
********
public class Form1 : System.Windows.Forms.Form // main form created with Designer
{
private Form2 frm2 ; // add it after finishing with Designer
// other members
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
frm2= new Form2(); // add it after finishing with Designer
frm2.Show(); // add it after finishing with Designer
}
// other members
static void Main()
{
Application.Run(new Form1());
}
}

Form2.cs
********

public class Form2 : System.Windows.Forms.Form // added with Designer
{
// members of this form
// no reference to the Form1
}

With that you have the both Form2 and Form1 and you can edit independently but when you close Form1 , Form2 will be also closed.
-obislavu-
 
Thanks for the help. I am just learning C#, and I find the best way to learn is to write programs.

Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top