In this form when correctly logged in I want to make the System->Log In and System->Register menu items visible = false, the Statistics and Forms menu items enabled.
Here is the code of the login button on successful logging:
Re: Access a MainMenuStrip subitem from a child form
Accessing form controls this way is not recommended - it's breaking encapsulation.
Large UIs can get really complicated if you have child forms accessing their parents directly - and it becomes impossible to know which window is causing certain behaviour. Maintenance hence becomes a nightmare.
All the software companies I've ever worked for would have you shot on sight if you did this as part of their development team because of its impact of how maintainable the application is.
Presumably your child form is being created by your MDI parent. If not, it should be.
Implement an event on your child form such as "LoggedIn" and hook into it when your MDI parent is created.
Fire the event when your child form is logged in and then the MDI parent can handle the event and set the relevant control states.
If you don't know how to write your own delegates & events I suggest you look here.
Re: Access a MainMenuStrip subitem from a child form
Darwen,
Thanks for your criticism, but I want to know to how to do this exactly the way I have described.
It's a project for the university, it is not for my employer and since it is a very simple application I have no problem with "Maintenance hence becomes a nightmare".
Re: Access a MainMenuStrip subitem from a child form
(1) I find bad habits are very hard to break. If you develop good habits in the first place then I tend to find life a lot easier. You have to learn good practice sooner or later so why not sooner ?
(2) Coding 'just to get it done' tends to cause you more headaches than doing things the tried and tested way.
(3) It's useful for you to learn events & delegates regardless as they're one of the most important and useful features of .NET.
(4) Doing it the way I suggest fixes your problem. It's the way that I would do it. And maybe you're having a problem because you're not using the correct method in the first place ?
Darwen.
www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.
Re: Access a MainMenuStrip subitem from a child form
Okay, this one is dropped.
Thanks darwen for the constructive criticism! I will learn more about delegates and events but had only 1 day to solve the problem -> found a workaround.
It's now time I visited the c# section as the next exam is coming this Saturday.
Bookmarks