I am trying to get access to a button that is inside a user control which itself is inside another window. I have tried both the lines of code provided below.
Button manpanel = Application.OpenForms["STAFFHOMEMENU"].Controls["MASTERDATABASE"] as Button;
Button manpanel = Application.OpenForms["STAFFHOME"].Controls["MAINPANEL"].Controls["STAFFHOMEMENU"].Controls["MASTERDATABASE"] as Button;
Any fixes or alternative ways of accomplishing this would be great, Sorry if the message is a little unclear.
When the code is run with either of these lines I get the following error : "System.NullReferenceException: 'Object reference not set to an instance of an object."