By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

add different user controls in main form panel

P: 1
i have main form which has one panel
i have two user controls uc1 and uc2
i am able to add uc1 in that panel
the problem is that i want to add fuctionality when i call my uc2 by clicking button present in uc1
so because of what my uc1 will hide n uc2 will appear at the same panel
Dec 9 '18 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,032
I do not understand your question much further than following response:

Expand|Select|Wrap|Line Numbers
  1. IF uc1.Text='Show uc2' THEN uc2.Visible=true ELSE c2.Visible=false
Does this help? if not please give some more info.
Dec 14 '18 #2

P: 7
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:

Expand|Select|Wrap|Line Numbers
  1. public static void showUC(Control uc, Control pnlContainer)
  2. {
  3.     pnlContainer.Controls.Clear();
  4.     uc.Dock = DockStyle.Fill;
  5.     pnlContainer.Controls.Add(uc);
  6. }
  7.  
and call it like this:

Expand|Select|Wrap|Line Numbers
  1. 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..
Dec 16 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.