XMLSerialize and Microsoft Controls
-
Sorry for posting this again. What I want to do is save the state of my windows form. What I heard so far XMLSerializing is a good way to go. If I got it right: Due to containing interfaces many classes can't be serialized. So the Form itself can't be serialized. So I need to serialize elements of this form. These are Controls (Labels and UserControls). If the above applies, I see no way doing so, except serializing lets say the Text of a Label and then later deserialize the string, create a new Label and set the Text to the deserialized string, which is a really bad situation. Is there any better way? Thanks for helping me out.
-
Sorry for posting this again. What I want to do is save the state of my windows form. What I heard so far XMLSerializing is a good way to go. If I got it right: Due to containing interfaces many classes can't be serialized. So the Form itself can't be serialized. So I need to serialize elements of this form. These are Controls (Labels and UserControls). If the above applies, I see no way doing so, except serializing lets say the Text of a Label and then later deserialize the string, create a new Label and set the Text to the deserialized string, which is a really bad situation. Is there any better way? Thanks for helping me out.
You don't need to recreate the controls dynamically. Just catalog the information you need to save, organize it into some XML format, then use XSD.exe or something like Skeleton Crew[^] to generate an XML serializable model. Then on form load, read the XML file and use the resulting model to update the controls affected by your information, and on form closing fill a model with your information and serialize it out to the XML file. You can restrict your data to the text in text fields, or the form's size, or whatever you want to persist. Keep it simple.
Try code model generation tools at BoneSoft.com.