1

Possible Duplicate:
C# Working with mutliple Forms

I have a c# program that I want to be able to have multiple users. Whenever the program is launched I want to bring up a Windows Form to display a box to select the user. I want to do all of this before displaying the main Windows Form. How can I accomplish this? I've already written the main application just want to be able to add multiple users now and not sure how to do this. Thanks

Community
  • 1
  • 1

2 Answers2

2

Quite simply, in your Main() function, use Application.Run to activate your preliminary form:

Application.Run(select_user_form);
selected_user = select_user_form.SelectedUser;
Application.Run(new MainForm(selected_user));
staafl
  • 3,147
  • 1
  • 28
  • 23
  • assuming that "user" is a concept internal to your application and we're not talking about selecting from windows user accounts, that's something else ... – staafl Aug 23 '12 at 17:04
0

In Program.cs file write this:

 frmUserSelection objUserSelectionForm = new frmUserSelection ();
 Application.Run(objUserSelectionForm);

 string userName = objUserSelectionForm.UserName;
 Application.Run(new MainForm(userName));

Here in frmUserSelection declare one string variable "UserName" and before closing that user selection form just assign selected user name to this variable and pass it to Mainform constructor and in mainform constructor fetch this value in other variable and use it!!

Hope it helps you to understand clearly!!

  • Thanks, just what I was looking for. More familiar with Linux and C++, just writing this program to learn C# mostly. – user1620479 Aug 23 '12 at 17:40