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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login form opens, call another form and close login

Status
Not open for further replies.
Sep 17, 2001
673
US
I have created a login form (form1) and a new form (form2). I am trying to call the new form after clicking ok button on form1 then close form1 so only form2 is shown. I am a FoxPro guy coming into the strange world of .NET. I am guessing that since form1 is the master that closing it will kill any child forms opened. So the question is how do others do this? Below is my crappy code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{


{
Form2 f2 = new Form2();

f2.Show();
this.Close();
}



}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}


}
}

Regards,

Rob
 
you can either do this.Hide() which just sets the visibility of the form - or you can modify the main() method to say

//Application.Run(new Form1());

Form1 f1 = new Form1();

if (f1.ShowDialog == DialogResult.OK)
{
Application.Run(new Form2());
}
 
You are killing the main thread.

Replace:
Code:
     Form2 f2 = new Form2();

     f2.Show();
     this.Close();

With:

Code:
     Form2 f2 = new Form2();

     this.Hide();
     f2.Show();
     this.Dispose(false);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top