I couldn't understand a lot but based on what I understood I am going to give u suggestion -
If you really want to do so you can write your code like this:
- public static void showUC(Control uc, Control pnlContainer)
-
{
-
pnlContainer.Controls.Clear();
-
uc.Dock = DockStyle.Fill;
-
pnlContainer.Controls.Add(uc);
-
}
-
and call it like this:
- showUC(new someControlType(), someControlContainer);
No need to call the GC; do leave it to the system to clean up matters!
And a static function needs to know all objects it is supposed to work with, so you need to pass in the container as well.
Finally new needs paranthesis with (optionally) parameters..
I made the signature of the new control Control so you can pass in any control; and for even more flexibility the container is also Control. Note that this still allows you to pass in the Form! Of course you may want to go back to more restricted types..