Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two forms.

1 form is mdiparent.
1 form is login form

login form is inside of mdi parent.


mdiparent has menustrip and it has..

menus called,
1. login
2. Reports

when you clicked login it will show username and password
if its correct
whole menu's in application will be enable to all users.

currently reports menu is disabled and i want to enable that if login is correct.

just go through my following codes.
C#
Form1 main = new Form1();

            main.Controls["Reprt1"].Enabled = true;

            main.Controls["Reprt2"].Enabled = true;

            main.Controls["Reprt3"].Enabled = true;

            main.Controls["Reprt4"].Enabled = false;



Error is this?
Object reference not set to an instance of an object.
Posted
Updated 25-Jul-14 0:31am
v2
Comments
hypermellow 25-Jul-14 6:27am    
Where in your code do you get the exception "Object reference not set ....." ?
What are you trying to do when referencing new Form1(),and from where?

1 solution

Um.
You don;t think it would be more useful to enable and disable the menustrip on the existing form instance? You know, the one the user can see?

At the moment, you are creating a new form instance and trying to change it's menustrip controls, assuming that they are directly attached to the Controls collection. First off, that won;t work, because anything you did change there would affect the new instance, and not the version that is being displayed, and secondly the actual report controls are contained within the actual MenuStrip object instance, not directly on the form surface.

Instead, do the code in the MDIParent form itself (so you affect the current instance) and use teh control name directly:
C#
Reprt1.Enabled - true;
Where "Reprt1" is the Name of the control as shown in the designer view Properties Pane.

If you need to do this while the login form is still displayed, then use an event to signal the main form that login has completed: Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900