I have a little problem with my simple login system.
this is the code
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool loginSuccessful;
bool loginRetry;
using (Login login = new Login())
{
loginSuccessful = (login.ShowDialog() == DialogResult.OK);
loginRetry = (login.ShowDialog() == DialogResult.Retry);
if (loginSuccessful)
{
Application.Run(new Form1());
}
if (loginRetry)
{
Application.Run(new Login());
}
}
}
}
It works but a little problem starts with these two lines :
loginSuccessful = (login.ShowDialog() == DialogResult.OK);
loginRetry = (login.ShowDialog() == DialogResult.Retry);
At firts the programm reaches the ‘loginSuccessful-line’, but when it reaches the next line the windows forms application starts to move from its position and waits for a new click on the login button before it decides to close itself and to move on the the next forms application or to stay at its place because of a wrong usercode/password combination.
how can I fix this ? Btw. this is .net, C#
I dont want the forms application to move 1 position from left to right and ask for a new click action.
A better aproach will be using FormClosing event in Login dialog, and if DialogResult is DialogResult.OK and user could is not authenticated, set the e.Cancel property to true, this way you don’t have to create new instances of the Login dialog neither call ShowDialog twice since it’s disposed when closed.
in Login dialog:
Main body: