Question : VS2008 C# DeskTop application Close form and open anther one problem

Dear EE
i am working with VS2008 and C#.
i make a form "Login"
i have an "MDIParent"
i want when user login to the system the login screen closes and the MDIParent opens
this is the code i wrote:
but it closes everything


please advise me what to do.
Code Snippet:
1:
2:
3:
4:
5:
6:
this.Close();
            MDIParent1 mDIParent1;
            mDIParent1 = new MDIParent1();
            mDIParent1.WindowState = FormWindowState.Maximized;
            mDIParent1.Show();
            mDIParent1.Activate();

Answer : VS2008 C# DeskTop application Close form and open anther one problem

Here is some code I just threw together to do this....

1) Change the login form into a dialog box (Code Provided for setting DialogResult from your form below Part 1)
      DialogResult.OK = successful login
      DialogResult.Cancel = failed login
2) Change out the main function in the Program.cs to show the dialog and on successful login display the MDIForm (Code also shown below Part 2)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
/************************************
 Part 1 -> Dialog box result
************************************/
// this is a the sample form I put together as a "login" form 
// I changed it out to be a dialog box
public partial class LoginForm : Form
	{		
		public LoginForm()
		{
			InitializeComponent();
			// initialize the Dialog Result for you Login Form
			this.DialogResult = DialogResult.None;
		}
 
		private void button1_Click(object sender, EventArgs e)
		{
			// this is where you set the result of the login attempt as a dialog result
			this.DialogResult = DialogResult.OK;
 
			// on login failure exit gracefully (or allow retry)
			//this.DialogResult = DialogResult.Cancel;
		}
	}
 
 
 
 
/************************************
 Part 2 show MDIForm based on DialogResult
************************************/
static class Program
	{
		/// 
		/// The main entry point for the application.
		/// 
		[STAThread]
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			
			// declare and initialize your mdiForm
			MDIForm mdiForm = new MDIForm();
			mdiForm.WindowState = FormWindowState.Maximized;
			
			LoginForm loginForm = new LoginForm();
			if (loginForm.ShowDialog(mdiForm) == DialogResult.OK)
			{
				// Application.Run will handle the calls to show and activate
				Application.Run(mdiForm);
			}
		}
	}
Random Solutions  
 
programming4us programming4us