?
Solved

Switching Between Usercontrols

Posted on 2007-07-31
7
Medium Priority
?
277 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:tolninja
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:gjutras
ID: 19603476
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
 
LVL 1

Author Comment

by:tolninja
ID: 19603502
I need to do this on a Windows App.  thx
0
 
LVL 6

Accepted Solution

by:
gjutras earned 2000 total points
ID: 19603623
ok, ignore the second option.  put your controls in seperate panel controls and then change the visible properties on the panels.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:tolninja
ID: 19604007
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
 
LVL 1

Author Comment

by:tolninja
ID: 19604171
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
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 19604515
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
 
LVL 1

Author Comment

by:tolninja
ID: 19613128
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question