How to save an object (control) to a textfile for re-use later?

  • Thread starter Thread starter JustMe
  • Start date Start date
J

JustMe

Hi:

Is it possible to save a few controls on a form to a textfile or
database so that they can be 're-initiated' in their previous state at
a later time?

I've heard of the OpenNetCF XML-Serializer ... would this work for
'controls'? Or does it only work for certain types of objects?

Any help would be appreciated.

--Terry
 
JustMe said:
Is it possible to save a few controls on a form to a textfile or
database so that they can be 're-initiated' in their previous state at
a later time?

I've heard of the OpenNetCF XML-Serializer ... would this work for
'controls'? Or does it only work for certain types of objects?

Hi Terry aka JustMe!

You can't successfully serialize and deserialze a control because
controls get a handle form the operating system at creation time. Of
course, this handle gets invalid once the control is destructed (which
is done if you dispose its container).

The only thing you can do is to create a class, for exmaple
"ButtonProperties", that can save the properties you want to save,
provide it with two methods, one that takes a button instance as an
argument and copies them to the class and one that copies the properties
from the ButtonProperties instance back to the button instance. You can
then serialize this instance. Of course, the creation of the button
itself has to be done by yourself.

HTH,

Michael
 
Back
Top