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();} } |
/** privatevoid 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();} } |

