How to access the menustrip control an mdiparent from its mdi child

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swatii
    New Member
    • May 2009
    • 15

    How to access the menustrip control an mdiparent from its mdi child

    I am using C#.net.My problem is that
    I have a MDI Parent form and on that I have menustrip control which i have disabled at the time of load of MDI parent.Now I have MDI child login form.
    Now If the valid user sign in then only that menustrip should be enabled.
    I used the below code on the "signin" button click event.
    MDIparent form1=new MDIparent();
    form1.menustrip 1.enabled=true;
    (modifier of menustrip is public).

    But this code is not working so may i know how to solve this problem.
  • swatii
    New Member
    • May 2009
    • 15

    #2
    How to access the menustrip control an mdiparent from its mdi child

    I am using C#.net.My problem is that
    I have a MDI Parent form and on that I have menustrip control which i have disabled at the time of load of MDI parent.Now I have MDI child login form.
    Now If the valid user sign in then only that menustrip should be enabled.
    I used the below code on the "signin" button click event.
    Code:
    MDIparent form1=new MDIparent();
    form1.menustrip1.enabled=true;
    (modifier of menustrip is public).

    But this code is not working so may i know how to solve this problem.

    Comment

    • swatii
      New Member
      • May 2009
      • 15

      #3
      waiting

      Is there any one who can solve my problem

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        But this code is not working
        What error do you get from this code?

        Comment

        • swatii
          New Member
          • May 2009
          • 15

          #5
          No Error!!!!

          Originally posted by tlhintoq
          What error do you get from this code?
          I am not getting any error but this code is not working....I mean still menustrip control is disabled...

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Originally posted by swatii
            I am not getting any error but this code is not working....I mean still menustrip control is disabled...
            Code:
            form1.menustrip1.enabled=true;
            There is really no way to misinterpret this code as doing anything other than enabling menustrip1.

            Now you are down to basic debugging.
            Using breakpoints and walking through the code line by line may discover that you are NOT actually running this line. Or maybe there is another line elsewhere that is disabling the menu again. Or maybe the menustrip sits inside another control that is disabled. Or maybe you have more than one menustrip in your application and you are enabling the wrong one.

            With only two lines of code provided its hard to give more advice.

            Comment

            • balame2004
              New Member
              • Mar 2008
              • 142

              #7
              You are creating new instance for the parent form and trying to enable the menustrip of the form instance.Defini tely it won't work as you need to make the changes in the actual instance of the parent form. Pass the actual instance of the parent form to login form and make the changes in it.

              Eg:

              Add the following constructor to your login form.

              private MDIparent parent=null;
              public LoginForm(MDIpa rent parent)
              {
              this.parent=par ent;
              }

              in your parent form call the constructor like this:
              LoginForm lgFrm=new LoginForm(this) ;

              Enable the menustrip in signin button click event method as follows.

              this.parent.men ustrip1.enabled =true;

              It will work.

              Comment

              • swatii
                New Member
                • May 2009
                • 15

                #8
                Thanks

                Wow ...This code works well thank you so much....Now I understand my mistake...

                Comment

                Working...