I recently refactored the code of a user control in my WinForms project, and changed it from a user control with text boxes, combo and buttons that were just placed all over it, to a user control that now contains a TableLayoutPanel, which holds all the controls in a better order.
My problem is that in many places the code address the controls nested in the user control directly via the Controls dictionary - for example: MyUserControl.Controls["NameOfTextBox"].Visible = false;
Now, after I nested the text boxes and buttons in a TableLayoutPanel, I can't do such addressing anymore, and now I should write MyUserControl.Controls[0].Controls["NameOfTextBox"].Visible = false;, because otherwise I get an exception.
My question is whether I should change all my code in every place that addresses the contents of the user control, or can you offer me some workaround to implement on the user control itself, so when I'll try address the controls directly, it will forward it to the contents of the TableLayoutPanel.
Any Ideas?