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
LVL 1
tolninjaAsked:
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.
0
 
gjutrasCommented:
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
0
 
tolninjaAuthor Commented:
I need to do this on a Windows App.  thx
0
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
0
 
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
0
 
REA_ANDREWCommented:
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

so

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.

Andrew

0
 
tolninjaAuthor Commented:
REA,
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
0
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.