How to Serialize System.Drawing.Pen

Discussion in 'ASP .Net' started by Sergio Dinis, Oct 2, 2003.

  1. Sergio Dinis

    Sergio Dinis Guest

    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.
     
    Sergio Dinis, Oct 2, 2003
    #1
    1. Advertising

  2. 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


    "Sergio Dinis" <> wrote in message
    news:...
    > 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.
    >
    >
     
    Jay B. Harlow [MVP - Outlook], Oct 3, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gina L. Hernandez

    ERROR TRYING TO PEN ONE APPLICATION

    Gina L. Hernandez, Jun 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    321
    Ken Cox [Microsoft MVP]
    Jun 4, 2004
  2. Gordz
    Replies:
    3
    Views:
    3,956
    John Oakes
    Jun 7, 2004
  3. Kevin Spencer
    Replies:
    0
    Views:
    381
    Kevin Spencer
    Jun 30, 2004
  4. Replies:
    1
    Views:
    661
    Kevin Spencer
    Jan 9, 2006
  5. defn noob
    Replies:
    1
    Views:
    415
    Mark Space
    Jun 28, 2008
Loading...

Share This Page