Reputation: 1877
I want to create two forms: LoginForm and BaseForm.
LoginForm is created first and it contains 'Login' and 'cancel' button . When user clicks 'Login' button then LoginForm should be closed and BaseForm should be created and opened.
When user clicks 'cancel' button of LoginForm then it should get closed.
How can I do it? Can anyone please give me good solution for this?
Solution:
In the main():
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm form=new LoginForm();
if(form.showDialog()==DialogResult.OK)
{
form.close();
Application.Run(new BaseForm());
}
else
form.close();
}
Upvotes: 1
Views: 2347
Reputation: 1804
private void buttonLogIn_Click(object sender, EventArgs e)
{
LoginForm loginForm = new LoginForm ();
loginForm .Show();
this.Hide();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
Upvotes: 1
Reputation:
I have an app that requires login and what I do in the initialization method is check to see if the user is logged in. If they are not I open a Modal with the login prompt. If they cancel that I close the app.
The code to show the modal:
var login = new Login();
login.ShowDialog();
The cancel button on login would call something like:
Application.Exit();
Upvotes: 1
Reputation: 613612
In your application's main function:
ShowDialog()
to show it modally.ShowDialog()
.Application.Run()
.If you do it in this order then the main form won't be shown until your user has finished with the login form.
Upvotes: 0
Reputation: 9469
You could simply open the main form, check if the user is authenticated. Then show the login form and if the user cancels the login form, just close the application.
Upvotes: 0