How to serialize a System.Windows.Form.Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there anybody who can help me to serialize a control
like buttons, textbox, and each other control?I don't
want to inherit from some of those.I try with
SoapFormatter but it tell it can't serialize the control
because it doesn't have the [Serialized] attribute. After
I try with a XmlSerializer but it tells that it can't
serialize it.Anyone has some idea?
 
Hi,

You can implement the ISerializable interface and write your own
serialization/deserialization code. This will work for binary serialization.
For the XML one, there's an unsupported IXmlSerializable interface you can
still implement to add custom XML serialization to your control. There's a
good Aaron Skonnard's article on how this is done.
 
In addition to Demitriy's suggestion.

You can define & register a Serialization Surrogate. That is define a class
that implements the System.Runtime.Serialization.ISerializationSurrogate
interface.

A Serialization Surrogate is a helper class that knows how to read the
values of the Control and save them in the serialization stream, it also
knows
how to deserialize the values and create the Control again.

Part 3 of the following 3 part MSDN Magazine articles covers
ISerializationSurrogate along with caveats on its use.

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

Hope this helps
Jay
 
Back
Top