Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#1: May 13 '09
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.menustrip1.enabled=true;
(modifier of menustrip is public).

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

Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#2: May 13 '09

re: 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.
Expand|Select|Wrap|Line Numbers
  1. MDIparent form1=new MDIparent();
  2. form1.menustrip1.enabled=true;
  3.  
(modifier of menustrip is public).

But this code is not working so may i know how to solve this problem.
Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#3: May 13 '09

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


Is there any one who can solve my problem
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,784
#4: May 14 '09

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


Quote:
But this code is not working
What error do you get from this code?
Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#5: May 17 '09

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


Quote:

Originally Posted by tlhintoq View Post

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...
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,784
#6: May 17 '09

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


Quote:

Originally Posted by swatii View Post

I am not getting any error but this code is not working....I mean still menustrip control is disabled...

Expand|Select|Wrap|Line Numbers
  1. 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.
Familiar Sight
 
Join Date: Mar 2008
Posts: 141
#7: May 18 '09

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


You are creating new instance for the parent form and trying to enable the menustrip of the form instance.Definitely 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(MDIparent parent)
{
this.parent=parent;
}

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.menustrip1.enabled=true;

It will work.
Newbie
 
Join Date: May 2009
Location: jaipur,India
Posts: 15
#8: May 18 '09

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


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