Solved

Can I make a UserControl static?

Posted on 2008-10-13
6
867 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:wsprhino
  • 3
  • 3
6 Comments
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 200 total points
ID: 22704256
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
 

Author Comment

by:wsprhino
ID: 22704678

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
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22708848
"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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:wsprhino
ID: 22709108

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
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22714001
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
 

Author Comment

by:wsprhino
ID: 22715873

Thanks, I will give it a try
Steve
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now