Login Screen

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

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.
 
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.
 
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.
 
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
 
Best way...:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top