how to access menu of MDI form from a child menu in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Teka Cherenet
    New Member
    • Feb 2011
    • 4

    how to access menu of MDI form from a child menu in C#

    I am trying to develop a small window application in C# as a front end and SQL server as a back end, but I couldn't make visibility false on the menu of MDI form from a child form. for example I want to make visibility of one of the menu that I created on the MDI form from a login form, for the case of the wrong user name and password entry.

    here is the code I write on the login form (which has two text boxes one for user name and the other for password and I have attached my MDI form.
    thank you.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.VisualBasic;
    using System.Data.SqlClient;
    
    namespace Lesson01.Security
    {
        public partial class frmLogin : Form
        {
          Utilities.frmMDI frmMdi = new Lesson01.Utilities.frmMDI();
           
            
            public frmLogin()
            {
                InitializeComponent();
            }
    
            private void frmLogin_Load(object sender, EventArgs e)
            {
                  
            }
            private void frmLoging_FormClosed(object sender, FormClosedEventArgs e)
            {
                Modules.modMain.frmLoging = null;
            }
    
            private void cmdOK_Click(object sender, EventArgs e)
            {
                string SQL = "";
                Class.clsConn dbConn = new Class.clsConn();
                
                SQL = "SELECT * FROM tblUser ";
                dbConn.Oreader(SQL);
                  if (dbConn.reader != null)
                    {
                        if (dbConn.reader.Read())
                        {
                            if (txtUserName.Text.Trim() != dbConn.reader.GetString(0) && txtPassword.Text.Trim() == dbConn.reader.GetString(1))
                            {
                                                         
                                MessageBox.Show("Please Enter Valid User Name");
                                txtUserName.Text = "";
                                txtUserName.Focus();
                                              frmMdi.mnuHelp.Visible = false;
                         frmMdi.mnuOptions.Visible = false;
                         frmMdi.mnuReport.Visible = false;
                         frmMdi.mnuTask.Visible = false;
                                                          
    
                            }
                       if (txtUserName.Text.Trim() == dbConn.reader.GetString(0) && txtPassword.Text.Trim() != dbConn.reader.GetString(1))
                            {
                                                            MessageBox.Show("Please Enter Valid password");
                                txtPassword.Text = "";
                                txtPassword.Focus();
                                          frmMdi.mnuHelp.Visible = false;   
                         frmMdi.mnuOptions.Visible = false;
                         frmMdi.mnuReport.Visible = false;
                         frmMdi.mnuTask.Visible = false;
    
    
    
                            }
                            if (txtUserName.Text.Trim() == dbConn.reader.GetString(0) && txtPassword.Text.Trim() == dbConn.reader.GetString(1))
                            {
                                Modules.modMain.userName = txtUserName.Text.Trim();
                                
                            
                            frmMdi.mnuHelp.Visible = true;
                            frmMdi.mnuOptions.Visible = true;
                            frmMdi.mnuReport.Visible = true;
                            frmMdi.mnuTask.Visible = true;
                                                           dbConn.cn.Dispose();
                                this.Close();
                               
                            }
                        }
    
                    }
    
                 }
    
            private void cmdCancel_Click(object sender, EventArgs e)
            {
                
                this.Close();
            }
    
          
           
        }
    }
    Attached Files
    Last edited by Aimee Bailey; Apr 4 '11, 06:46 PM. Reason: Placed code within code tags.
  • Teka Cherenet
    New Member
    • Feb 2011
    • 4

    #2
    how to access menu of MDI form from a child menu in C#

    I couldn't make visibility false of menu in MDI parent form from a child form in C#.
    for example I have a MDI form which has two menus (Maintain and Task) and on the first menu I have a sub menu called "Maintain Item" so I need to make visibility false for the sub menu from a child form eg. from a login form.
    any help would be appreciated.
    Thank you.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      HAve you tried changing the Enabled property of the menu item?
      Last edited by Plater; Apr 11 '11, 05:08 PM.

      Comment

      • Teka Cherenet
        New Member
        • Feb 2011
        • 4

        #4
        yes I have checked it and it is true. but I need to make visibility false for the case of the user enters wrong user name and/or password. but if the user enter valid user name and password on the login form the menus which are on the Main MDI form will be displayed (the visibility is true).

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          I think menus have an event that is something like "before popup" which fires before the menu is shown.
          You could do your logic about verifying if the user is correct and blank out the item then?

          Comment

          Working...