469,271 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Login Screen

What is the best way do a login screen? I have the Main() method in my
login screen. After iit checks the userid and password the OK button
loads the main application form but the next line is frmLogon.Close()
which closes the whole application! If I hide it, the app does not
close completely. Thanks.

Nov 16 '05 #1
6 22603
Hi,

I guess you have at least 2 forms (login form and form for the application
itself). You can show the login from when your application is starting -
then check for username and pass and close both forms or just close the
login from.

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Marty" <ma********@absu.accenture.com> je napisal v sporocilo
news:11**********************@g14g2000cwa.googlegr oups.com ...
What is the best way do a login screen? I have the Main() method in my
login screen. After iit checks the userid and password the OK button
loads the main application form but the next line is frmLogon.Close()
which closes the whole application! If I hide it, the app does not
close completely. Thanks.

Nov 16 '05 #2
2 forms -

Main form and login form.
LoginForm shown as Modal Dialog Window as a child of MainForm.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Marty" <ma********@absu.accenture.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
What is the best way do a login screen? I have the Main() method in my
login screen. After iit checks the userid and password the OK button
loads the main application form but the next line is frmLogon.Close()
which closes the whole application! If I hide it, the app does not
close completely. Thanks.

Nov 16 '05 #3
If I close the login form the whole application closes even if I load
the app form first. I can get around this by using frmApp.ShowDialog
so frmLogin.Close() dosen't happen until frmApp is closed but I
shouldn't have too.

Nov 16 '05 #4
LoginForm (e.g. 2 textboxes, 1 button):

private void button1_Click (...)
{
// check for valid username and password
if (textBox1.Text == "someusername" .... )
{
this.DialogResult = DialogResult.OK
}
}

MainForm:

private void Form_Load (...)
{
LoginFrm frm = new LoginFrm ();
if (frm.ShowDialog (this) == DialogResult.OK)
{
// username and pass are OK
return;
}
else this.Close (); // close the form
}

Hope this helps
--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Marty" <ma********@absu.accenture.com> je napisal v sporocilo
news:11**********************@f14g2000cwb.googlegr oups.com ...
If I close the login form the whole application closes even if I load
the app form first. I can get around this by using frmApp.ShowDialog
so frmLogin.Close() dosen't happen until frmApp is closed but I
shouldn't have too.

Nov 16 '05 #5
Peter,
Thanks for the code. It solved my problem.
Marty

Nov 16 '05 #6
Best way...:

static void Main()
{
LoginDlg ld = new LoginDlg();
if (ld.ShowDialog() == DialogResult.Ok)
Application.Run(new Form1());
}

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mohan | last post: by
reply views Thread by JIM.H. | last post: by
1 post views Thread by leovega | last post: by
3 posts views Thread by bala | last post: by
10 posts views Thread by =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.