I am trying to enable admin privileges on my startup form. For this I've created an admin toolstrip login which would cause a password form to launch. I am however unable to update the startup form through the password form. I've seen a similar article over here [Why the controls not update, when call method from other form but this hasn't helped me solve my problem. My code is as below and what I have achieved so far is as below:
// Code for startup form...
public partial class StartupForm : Form {
private void adminToolStripMenuItem_Click(object sender, EventArgs e) {
FrmAdminPassword frmAdminPassword = new FrmAdminPassword();
frmAdminPassword.Show();
//this.Close();
//AdminLogin();
}
public void AdminLogin() {
loginToolStripMenuItem.Enabled = false;
logoutToolStripMenuItem.Enabled = true;
cmb1.Enabled = true;
btn1.Enabled = true;
tab1.Enabled = true;
tab2.Enabled = true;
tabControl1.TabPages.Add(tabAdminTasks);
MessageBox.Show("Admin Logged In");
}
}
// Code for password form
public partial class FrmAdminPassword : Form {
private void btnLoginAdmin_Click(object sender, EventArgs e) {
if (mskAdminPassword.Text == "password") {
StartupForm frm = new StartupForm();
frm.Show();
frm.AdminLogin();
this.Close();
}
else {
MessageBox.Show("Not a valid password");
this.Close();
}
}
}
If I implement it this way, what happens is that the original instance of the startup form is still present as a duplicate instance with all tabs and controls disabled and a new form is launched with all controls enabled.
What I actually want to achieve is:
- Click on the
adminToolStripMenuItem
. - Launch the
FrmAdminPassword
. - Enter the password and hit Login on
FrmAdminPassword
. - After hitting Login, close the
FrmAdminPassword
and enable the controls onStartupForm
.
Could someone please help on this? Thanks.