I am trying to make a form that verifies user login. I want that form to show first then, if the user login is successful, the main form should show.
this is what I have tried(in the second form):
private void button1_Click(object sender, EventArgs e)
{
string funame = "thename";
string dep = "thedep";
string unm = "theusername";
string ups = "thepassword";
User cs = new User(funame, dep, unm, ups);
if (cs.validateLogin(unm, ups));
{
MessageBox.Show("Welcome " + funame + " of " + dep);
frmPurchaseDiscountedItem fpd = new frmPurchaseDiscountedItem();
fpd.Show();
}
}
The problem is the main form always pops out first.
It should be something like:
*2nd form pops up then, if user is verified, main form pops up
Here is a workaround.
You don't need to change "start form" in
Program.cs. You can open the main window at the beginning and hide it. Then create a Login instance and show it.If login button in
Login formclicked, show theMainFormand closeLogin form.In addition, if you click the
X buttonin the upper right corner of theLogin form, it will also show the hiddenMainForm(if user doesn't want to login, close the application). We can avoid it by overridingWndProc.