Hi all, a n00b question regarding controls in a splitcontainer. I have a form (name it form1) with a splitcontainer containing 2 panels (panel1 and panel2). UserControlX is a usercontrol-form which is loaded in panel1 when form1_load(s). UserControlX-form has a buttonA. When i click on buttonA, form3 (another form) should be loaded in panel2: this is where i don't get it. The buttonA has the code:
form3 x = new form3();
//temp = solution name
temp.form1.splitContainer1.Panel2.Controls.Add(x);
x.Show();The error i get for splitcontainer1 = "is inaccessible due to its protection level "
ps. when the button is placed within panel1 (realtime in the form), said code works. instead of temp.form1, "this." is used.
can someone help me out with this.
ps. this is not a MDI thing..
Loading
iam thethingPosted Apr 11, 2007, 7:28 AM
I thought something was wrong with multiple forms within a from. Instead of a form containing the controls i now use a UserControl (VS2005 -> add items .... UserControl).
again thank for the help.
SokakPosted Apr 10, 2007, 6:06 PM
But yes, it can be done. What you need to do is go to the form with the Splitter, and in the splitter's property sheet change the value of "Modifiers" from 'private' to 'internal' or 'public'
Why it's not a good idea:
Form B should never directly access Form A's UI fields directly, this would normally be done by Form B raising an event to Form A to let Form A code control its own layout (Creating a new control and loading it into its panel). Having one object or form "touch" another can lead to all kinds of problems because if someone tells you that Form A is behaving incorrectly you can't just track the problem down in Form A. (This is especially a big problem when you aren't the only developer working on the project. The person responsible for Form A has no idea who's or what code is modifying it.) Each form and class should encapsulate its own functionality as much as possible and provide doorways via methods and/or call-back delegates (or events) to ensure that anything that should be interacting with them is doing so on this class' terms.