How to Serialize System.Drawing.Pen

S

Sergio Dinis

Hi All.
Anybody know how can I serialize an instance of System.Drawing.Pen?
I already have an idea but can't work. It consists of creating a new class
witch derives from Pen, but Pen is sealed. The only way I know is to create
a new class witch implements System.Runtime.Serialization.ISerialize that
has a Pen.

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Sergio,
Anybody know how can I serialize an instance of System.Drawing.Pen?
You can't as it does not have the Serializable attribute attached.

I would consider defining a Serialization Surrogate for it, 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 Pen and save them in the serialization stream, it also knows
how to deserialize the values and create a Pen 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/

The example is in C#, however its straight forward enough it should be
easily converted into VB.NET.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top