hi guys can some one help me out I have an application with two form on a first form's load event I have a condition where I check for something if it passes then I hide it and show the secong one but the issue is even if I hide it it still shows(ib if I do it on a btton click event it hides just fine ) below is my code
private void frmCreateDb_Load(object sender, EventArgs e){
frmMenu menu = new frmMenu(); try{
if (!Boolean.Parse(Settings.Default.sFistTimeRun.ToString())){
this.Hide();menu.Show();
}
else{
menu =
null;}
}
catch(Exception ex){
MessageBox.Show(ex.Message);}
}
Niradhip ChakrabortyPosted May 21, 2009, 6:46 AM
You have some options; you could withhold display of the main form until code 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();
}