简体   繁体   中英

How to display login form again after invalid login?

how can i redirect back to the Login form in win form application after invalid login write now i am trying this in program.cs

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new frmLogin());
frmLogin fm = new frmLogin();

fm.ShowDialog();
if (fm.DialogResult == DialogResult.OK && Global.Login)
    Application.Run(new MDIParent1());
else if(fm.DialogResult==DialogResult.Cancel)
{
    MessageBox.Show("Wrong Username Or Password");
    Application.Run(new frmLogin());
    //fm.ShowDialog();
}

Why are you not handling the "Invalid Login" in the Login form itself? Dont return to the calling form until the login is valid.

on frmLogin implementation check validity and show message box:

// in frmLogin.cs
if(/* loginn is valid*/)
{
    this.DialogResult = DialogResult.OK;
    this.Close();
}
else
{
    MessageBox.Show("Wrong Username Or Password");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM