I have a main form and login form.
I'm calling login form from main form but I can't get to disable main form(I can click on menu)
and also when i click on cancel button(in login form), I want to close both forms.
How to do that?
I have a main form and login form.
I'm calling login form from main form but I can't get to disable main form(I can click on menu)
and also when i click on cancel button(in login form), I want to close both forms.
How to do that?
Know the answer? Post it. Somebody with the same question will find it here.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted May 15, 2009, 1:33 AM EDT
To close them from some other form, replace 'this' with a reference to the Mdi Parent form.
To hide menu you can use following method:
You have some options; you could withhold display of the main form until the user was validated, and then hide the login form and open the main mdi form. To do what you have asked, a simple way to do it would be to set the menu's modifier property to public to make it available to your login form.
You can initialize the main form using something like this:
public Form1() { InitializeComponent(); // disable the menu this.menuStrip1.Enabled = false; this.WindowState = FormWindowState.Maximized; // open the login form frmLogin f = new frmLogin(); f.MdiParent = this; f.Show(); }Then, in whatever code runs within your login, once the user was validated, you could do something like this from the main form to enable the main form's menu and to dispose of the login form:
private void button1_Click(object sender, EventArgs e) { // do whatever you are going to do for the login // and if the test is passed, enable the menu and // dispose of the login form ((Form1)(this.MdiParent)).menuStrip1.Enabled = true; this.Dispose(); }