Switching Between Usercontrols

I have a Windows form that has two usercontrols.  I need to be able to switch back and forth between usercontrols using a button on each usercontrol.  Anyone know HOW this can be done?  I'm using visual studio 2005 c#.  Thanks
Who is Participating?
gjutrasConnect With a Mentor Commented:
ok, ignore the second option.  put your controls in seperate panel controls and then change the visible properties on the panels.
put each control in a panel and either on server side change the visible properties, or on the client side put each one in a div and using javascript set the style of the divs to display:none or inline
tolninjaAuthor Commented:
I need to do this on a Windows App.  thx
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

tolninjaAuthor Commented:
How to I access the panel from the usercontrol to change the visibility status?  Can you give me an example of the code?  thx
tolninjaAuthor Commented:
Oh... I think I understand.  You don't control the panel visibiliy from the usercontrol.  You control it in the panel.  That makes since.  It's going to make things a bit more sloppy, but I guess you've gotta do what you've gotta do.  Thanks for the advice.  I'm going to leave the question open for a bit longer to see if there are any better solutions out there.  thx
Make one more control. Which will be a UserControl.....Control if you will

Then In each UserControl you set an Event called Activated for example

Your UserControl "CONTROLLER" wires into this event. So take this scenario for example

UserControlA is Visible.  It has a button called "Activate UserControl B"

When this is clicked it triggers the event of say User Control Activation.  The Controller then sets the currently visible user control to be hidden and the UserControl that is hidden to be displayed.

So you need one event per UserControl

On Extra UserControl which is like the Switch


Another way would be to declare an instance of the opposite User Control in each User Control


User Control A has an instance of User Control B

User Control B Has an instance of User Control A

You then have access to each to switch between visibility.


tolninjaAuthor Commented:
I don't think that will work because the usercontrols have to be able to function by themselves.  It won't let me add an event to them because they have the Main() funciton.  The error I get is "... has more than one entry point defined".  thx
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.