Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two different windows forms in C#

I am new to C# and .NET programming. I want to design an application that opens up with a small login screen and when user presses the "Login" button, my program should close the login form and pass to a new form. How can I achieve this simple process?

Thanks.

like image 610
fantoman Avatar asked Feb 05 '26 09:02

fantoman


1 Answers

This could be a solution;

In LoginForm;

public bool IsLoggedIn { get; private set;}
public void LoginButton_Click(object sender, EventArgs e)
{
  IsLoggedIn = DoLogin();
  if(IsLoggedIn)
  {
    this.Close()
  }
  else
  {
    DoSomethingElse();
  }
}

In program.cs

static void Main()
{
  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  LoginForm loginForm = new LoginForm();
  Application.Run(loginForm);
  if (loginForm.IsLoggedIn)
  {
    Application.Run(new OtherForm());
  }
}
like image 135
Ali Ersöz Avatar answered Feb 07 '26 23:02

Ali Ersöz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!