How to call a form from another form?

noodlesoup

Newcomer
Joined
Aug 5, 2007
Messages
6
I have create 2 form within my C# project.
form1 is named login.
form2 is named main.

login form is used to verify username and password.
once the username and password is verified, login form will terminate and call form2 to enter the main screen.

I am having trouble calling form2.
Anyone know how to do this within Visual Studio C++?
 
Last edited:
I personally wouldn't recommend this technique. It would probably work, but it prevents the login form from being properly disposed and might cause obscure errors or problems down the road.

Multiple forms like this should be managed with the Application class. The simplest way to do this would probably be to duplicate the Application.Run in your Main() and specify the second form. The login data should probably be stored in your Program class or passed on to your main form.

Your main should probably look something like this:
C#:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
	Application.EnableVisualStyles();
	Application.SetCompatibleTextRenderingDefault(false);
	login loginForm = new login();
	Application.Run(new loginForm());
	// Place code to manage login data here
	Application.Run(new main()); // (or whatever your main form's class is called)
}
 
Back
Top