Link to home
Start Free TrialLog in
Avatar of tolninja
tolninja

asked on

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
Avatar of gjutras
gjutras

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
Avatar of tolninja

ASKER

I need to do this on a Windows App.  thx
ASKER CERTIFIED SOLUTION
Avatar of gjutras
gjutras

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How to I access the panel from the usercontrol to change the visibility status?  Can you give me an example of the code?  thx
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

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

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