So it's been a very long time since I've worked with C# and am feeling like a newbie all over again. I'm creating a simple GUI in a project that uses an API, and I need to create a simple login form. I have secondary form pop up when someone clicks "Login" on the main form that prompts for the username and password, which would then close that form and stores the information in that class. Problem is, how would I know when that form is closed?
Is there an easier way to do this, or a way to return the username and password when the login button is clicked on the secondary form?
The basics of my code are as follows:
Main.cs
namespace My_Namespace {
public partial class frmMain : Form {
public frmMain() {
InitializeComponent();
}
}
private void mnitLogin_Click(object sender, EventArgs e) {
Login login = new Login();
login.ShowDialog();
}
}
Login.cs
namespace My_Namespace {
public partial class Login : Form {
private String Username;
private String Password;
public Login() {
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e) {
Username = txtUsername.Text;
Password = txtPassword.Text;
this.Close();
}
public String getUsername() {
return Username;
}
public String getPassword() {
return Password;
}
}
}