I created a login form in c#. If a user signs in with the right password en username and clicks on 'Login' then the seconds form opens. How to close the login form after the last step?
A:
You can type
FormName.ActiveForm.Close();
It closes the current active form.
Royson
2010-01-07 12:38:56
A:
I would do a ShowDialog() of the Login Form from the main form.
After the login form closes you are back in the main form.
private void Form1_Load(object sender, EventArgs e)
{
var foo = new Form() { Text = "Login" };
if (foo.ShowDialog() == DialogResult.OK)
{
...
}
}
Louis Haußknecht
2010-01-07 12:53:23
+1
A:
Change your Main() method in Program.cs to display the login dialog. Don't start the message loop unless a valid login was entered. For example:
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var login = new LoginForm()) {
if (login.ShowDialog() != DialogResult.OK) return;
}
Application.Run(new Form1());
}
Your LoginForm should set its DialogResult property to OK if it detected a proper login.
Hans Passant
2010-01-07 13:59:35
;-) thk u very much!!
Sjemmie
2010-01-07 16:00:13