简体   繁体   中英

Closing a MessageBox but keeping Form Open

I've made a form that a user logs in with a username and password. If the password is incorrect I have a messageBox RetryCancel. I want a user to click Retry and have the message box close while keeping the Login form still up, so the user can try to login again.

I've tried a lot of different options, basically all I get is a infinite loop or the all of the windows close. Here is what I got so far. Thanks,

if (line != PassWord)
do
{
        result = MessageBox.Show(message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
        result = DialogResult.Retry;
        this.Close();
} while(result == DialogResult.Retry);
if (line == PassWord)
{
    Close();
}
if (line != PassWord)
{
    var result = MessageBox.Show(message, "Error", MessageBoxButtons.RetryCancel,    MessageBoxIcon.Information);
    if (result == MessageBoxResult.Cancel)
    {
        // User chose cancel, close app or whatever
    }
    else
    {
        // User pressed retry, nothing really happens
    }
}       
else if (line == PassWord)
{
    Close();
}

why don't you design a simple login form and check the login username and password on the login button. If authentication fails then simply display the message box saying "Check username and password" with okonly option.

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