Can I make a UserControl static?

I have a user control, just a collection of buttons and combo boxes really. The UserControl can appear on multiple other forms and panels and it would be good to keep them all in synch. The easiest way to do this it seems is to make the the usercontrol static  but I am not sure.

Is this the way to go? Will I have problems just marking the control as static or will VS designer have problems make the conversion? Or, is there a better way to do this. All the forms and usercontrols on which thecontrol appears report back to the same main form.

Thanks for any ideas,

Steve
wsprhinoAsked:
Who is Participating?
 
RamuncikasCommented:
There is no way to make control static for various reasons. But this "simulation" could be easily implemented.

One way would be to create class that would be a kind of datasource for your control and put is into session. All your controls could reference the same class in session and then set all changes back to it. Then control of the same type on the other page could get all data from this class with changes made in previous page.

If you give some more info about what you're up to or ask some more specific questions then we could be more helpful.

BR,
R
0
 
wsprhinoAuthor Commented:

The application I have has about 5 applications each with its own form.
  Each application form consists of a tool strip a viewbox for generating pictures, and a panel for allowing the user to modify what he sees.

Each application has various input data that can generally be grouped into categories. E.g. fill color for the different shapes and color, style to draw the edges of the shapes. Some of these are common to more than one of the applications. All this data fits on the panel grouped into regions.The panel can be hidden.

Also, the toolstrip has buttons which allows a form to be popped up for each of the input 'sub panels' of the input panel. For some of the applications the application may be too large for a small screen. So, thie  toolstrip buttons are an alternative way of input.

I have created the subpanels as controls but when these are placed on the input panel and the pop up forms I want them to always to be in synch.

Another reason for wanting common code is that some of the panels have a lot of buttons used for entering colors. Each of the ColorButtons when clicked pops up a tabbed pane for choosing a color somewhat similar to what VS has in its Property panel for choosing a color. Each of these buttons at the moment contains  a list of all the colors available or created by the user. This is a lot of duplication when each 'application' can have up to 20 ColorButtons and the only difference between them is the sort order of the colors.
 
At the moment the main form has control and receives notification when something has changed on one of the sub panels. It is responsible for informing the PopUpForm or InputPanel that something has changed on the other.

I just feel there should be a better way to do this that allows synching to be done automatically. Because if I change the contents of a subpanel the ApplicationForm needs to know to tell the InputPanel or the PopUp what has changed.

Also my list of colors is large and doesn't just consist of simple colors. Currently around 400 of them.

Hope this gives you a general idea of what I am trying to do and why.

Steve
0
 
RamuncikasCommented:
"The application I have has about 5 applications each with its own form"

Could you please explain me this? Is it 5 different .exe files or just one single applications with 5 different forms?

R
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wsprhinoAuthor Commented:

looking back the 5 applications are actually 5 UserControls that all have the same layout and so appear to overlay each other exactly. There is only one exe and one main form. Sorry, that was a mistake. But, ultimately there will be many more 'applications'. Some will be very similar while others will be quite different. But, they will all have the same general layout : a toolstrip, a viewbox and an input panel, plus the various mini-input panels that can be launched from the toostrip.
0
 
RamuncikasCommented:
So more or less solution could be the same. Define some static class to store settings for each of your control. Each control changes settings in that class upon user interaction. In other form other control of the same type could bind to same static class.

In short your controls would be instances but their datasource would be static class what would make it look like the same control instance is used all over application.

R
0
 
wsprhinoAuthor Commented:

Thanks, I will give it a try
Steve
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.