Static component - is it possible?

Is it possible to create a component that behaves like static - each time you put it into the designer's tray it is the same instance of the component

For example, I have a collection of styles, brushes, etc., which is a component. I also have a couple of forms, each needs the collection. I put the collection for each form into it's components' tray. Each time a new instance of the collection is created. I want this collection to be the same instance for each form - a kind of static. Is it possible

Thanks,
truetype


Answer this question

Static component - is it possible?

  • Vibhu Bansal

    What do you prefer - to put control, set its position, properties in the designer or to create it manually setting the coordinates of location on the parent control, etc. No doubt - everyone chooses the first. That's why I'm trying to create such a component - just to make me feel little bit more comfortable while working with it.

    As for the rest, thank a lot for you answer :)



  • withersd

    Can you please show the fragment of code with such type converter

  • LPXO

    Making your class a component so that it can be "added" to a form will not reduce your workload any; you will still have to write code to use its properties, just like you would if it were a singleton class.

    The answer to your original question is, yes, it can be done, if you write a custom type converter that can convert your object to an InstanceDescriptor that can be serialized into InitializeComponent. If your goal is to not do manual coding, then that is not the way you want to go.



  • HaggaiS

    I still do not believe that adding a singleton instance of a class like the one you describe to a form as a component will do you any good. Regardless, the more I think about it, the more difficulty I have in coming up with any reasonable way to accomplish it (probably because the designer was not built to do it, for the reasons I have already described). I'm not sure it can be done at all.

  • Joie Cariaga

    I want to work using the designer not by coding with hands to the most possible extent the visual studio can give me.

  • LeandroTubia

    up!

  • Fred Reimer

    Why would you make your class a component Just make it a singleton class, or make all of its members static, so that anything that needs it can access it.

  • Static component - is it possible?