locked
Panel is not marked as serializable. RRS feed

  • Question

  • Hi all!

    I'm considering creating my custom Tab Strip control. It simply contains a collection of panel, and an active panel where is the top panel to be draw. 

    But the Panel class is not marked as serializable, even I've created an inherit usercontrol from that with some overrides at the property and adding serializable attribute.

    What should I do now??


    Call me Zenocoding

    Thursday, August 8, 2013 2:07 PM

Answers

  • Hello,

    You can refer to the following thread about winform serialize:

    http://stackoverflow.com/questions/3597472/marking-a-winforms-button-as-serializable

    Find the line that looks like public partial class Form1 : Form. Right above it, place [Serializable]. That marks your class for serialization. You will need to control your own serialization however, since as noted below, UI objects do not serialize. For that, look at the ISerializable interface.

    More information about SerializableAttribute is here.

    But I think you can consider refer to this page:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/22e97ad6-04f0-46e6-a537-dff809f0a891/converting-controls-to-binary

    Refer to the article like the following

    "

    The following article will show you how to serialize the winForm control. Because of there’re some controls and properties have not implement the Iserializable interface, so we cannot serialize these controls immediately. But one way is we can implement our own controls to implement the Iserializable interface.

     

    How to Clone/Serialize/Copy & Paste a Windows Forms Control

    In the .NET environment, the System.Windows.Forms.Control class and all the concrete controls derived from it don’t have clone methods and they are not serializable. So there is no immediate way to clone, serialize, or copy & paste them.

    This article presents an all-purpose approach to let you clone, serialize, or copy & paste a Windows Forms control through serializing its properties.

     

    After we can serialize the winForm controls, let’s restore the serialized object into xml in C#.

    How to serialize an object to XML by using Visual C#

    This step-by-step article describes how to serialize an object to XML by using Visual C#. This method is useful for persisting the state of an object. This method is also useful for cloning an object by de-serializing the XML back to a new object.

    "

    Regards,


    Barry Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Barry Wang Monday, August 12, 2013 1:14 AM
    Friday, August 9, 2013 10:56 AM
  • Thank you, I've tried that, placing and removing the Serializable many times, but no helps. Then I just found this: Creating a Multi-Page Windows Forms Control with Design Time Support on CodeProject. That helped me much. I thinked again, instead of using a collection of panel, use the built-in Controls property for this, and build a designer for the tabs. Using the Controls property is much more naturally than using a collection in designer codes, since i just starting arround serialization and does not have much knowledge about it.


    Call me Zenocoding

    • Marked as answer by Barry Wang Monday, August 12, 2013 1:14 AM
    Saturday, August 10, 2013 3:05 AM

All replies

  • Hello,

    You can refer to the following thread about winform serialize:

    http://stackoverflow.com/questions/3597472/marking-a-winforms-button-as-serializable

    Find the line that looks like public partial class Form1 : Form. Right above it, place [Serializable]. That marks your class for serialization. You will need to control your own serialization however, since as noted below, UI objects do not serialize. For that, look at the ISerializable interface.

    More information about SerializableAttribute is here.

    But I think you can consider refer to this page:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/22e97ad6-04f0-46e6-a537-dff809f0a891/converting-controls-to-binary

    Refer to the article like the following

    "

    The following article will show you how to serialize the winForm control. Because of there’re some controls and properties have not implement the Iserializable interface, so we cannot serialize these controls immediately. But one way is we can implement our own controls to implement the Iserializable interface.

     

    How to Clone/Serialize/Copy & Paste a Windows Forms Control

    In the .NET environment, the System.Windows.Forms.Control class and all the concrete controls derived from it don’t have clone methods and they are not serializable. So there is no immediate way to clone, serialize, or copy & paste them.

    This article presents an all-purpose approach to let you clone, serialize, or copy & paste a Windows Forms control through serializing its properties.

     

    After we can serialize the winForm controls, let’s restore the serialized object into xml in C#.

    How to serialize an object to XML by using Visual C#

    This step-by-step article describes how to serialize an object to XML by using Visual C#. This method is useful for persisting the state of an object. This method is also useful for cloning an object by de-serializing the XML back to a new object.

    "

    Regards,


    Barry Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Barry Wang Monday, August 12, 2013 1:14 AM
    Friday, August 9, 2013 10:56 AM
  • Thank you, I've tried that, placing and removing the Serializable many times, but no helps. Then I just found this: Creating a Multi-Page Windows Forms Control with Design Time Support on CodeProject. That helped me much. I thinked again, instead of using a collection of panel, use the built-in Controls property for this, and build a designer for the tabs. Using the Controls property is much more naturally than using a collection in designer codes, since i just starting arround serialization and does not have much knowledge about it.


    Call me Zenocoding

    • Marked as answer by Barry Wang Monday, August 12, 2013 1:14 AM
    Saturday, August 10, 2013 3:05 AM