Enabling my disabled menuItems

I have an Mdi parent form called home which has other child forms. My parent form on form_load disables all the menuItems on it except the file menuItem. The file menuItem has login as one of the items. When you click login submenuItem it shows a new login child form t. The login form has a button called login. The click of the login button should fire an event that will enable all the disabled menuItems on the parent form. However, the method I wrote to enable the menuItems on the parent form does not work. It throws an exception. How do I enable the disabled menuItems. Below are my Codes. I need the necessary steps to make my forms work as they should.

//to disable all menu items on the main page. This code is in the parent form(home)

publicvoid disableMenu(){

mnuLogout.Enabled =false;

mnuLog.Enabled=false;

mnuContracts.Enabled =false;

mnuContacts.Enabled =false;

mnuAdmin.Enabled =false;

mnuReport.Enabled =false;

mnuHelp.Enabled =false;

mnuWindow.Enabled =false;

}



// code to enable disabled menuItems on the parent form

publicvoid enableMenu()

{

try

{

home myOwnHome =new home();

myOwnHome.mnuLogout.Enabled =true;

myOwnHome.mnuLog.Enabled=true;

myOwnHome.mnuContracts.Enabled =true;

myOwnHome.mnuContacts.Enabled =true;

myOwnHome.mnuAdmin.Enabled =true;

myOwnHome.mnuReport.Enabled =true;

myOwnHome.mnuHelp.Enabled =true;

myOwnHome.mnuWindow.Enabled =true;

this.Close();

}

catch(Exception exception){

MessageBox.Show(exception.ToString());

this.Close();

}

}




/**this codeisin the login form


private
void btnLogin_Click(object sender, System.EventArgs e)

{


/**
to enable entry of data into a database

*the username field cannot be empty. Also when

the buttonis clicked, the Main menuis enabled**/

try

{

if(txtUserName.Text =="")

{

MessageBox.Show("User name field cannot be empty");

}

else

{

enableMenu();

this.Close();

}

}



[5706 byte] By [Derry1406] at [2007-12-16]
# 1
Just a guess since yiour are not showing were the exception takes place or what it is:

You are having a problem referencing the correct instance of your parent form!

DMan1 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thank you very much for your prompt response. I just realised that no exception is thrown when I click on the login button. The code just does not work. I dont know why this is happening. Please you can let me have your email address so that we can review my project together. I appreciate every help you are expending on my behalf. Many Thanks,

Derry

Derry1406 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
To be able to access anything in the parent form, you must pass a reference to it
to the child form.

i.e.
You have a parent form called 'frmParent' and a child form called 'frmChild'.
In the definition section of frmChild you must have a variable declared like so:

frmParent myParent = new frmParent(); // Sorry, I'm a c# programmer.

Then when you create your instance of your child form from the parent you
do the following:

frmChild myChild = new frmChild();
frmChild.myParent = this;
frmChild.Show();

You can now access any public properties in frmParent from frmChild.
Email me if you want any further help. (mrsnipey@gmail.com)

MrSnipey at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Thanks for your assistance. However when you do this :
frmChild myChild = new frmChild();
frmChild.myParent = this;
frmChild.Show();

the new instance of the child form cannot access methods of the parent form. Basically I'm new to c# and my major headache is forms accessing methods and properties of other forms in the same solution. Kindly let me how I can find my way around this problem. I'd send you an email with the entire solution.

Thanks,

Derry

Derry1406 at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified