Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have form that generate new form with multiple textboxs and labels how save new form and can retrieve it again in another time ?
xml file can help me in that problem ??

What I have tried:

Save your WinForms User Control Data to XML[^]
but can't run that anyone help me Vb.net or C# ?
Posted
Updated 15-Sep-18 9:22am

A form, and the controls on it, are not "savable".

You have to build your own data structure to populate with the data from the properties of the form and controls so as you have sufficient information to read back the data and use it to recreate the form and controls. This is stuff like the form/control type, Top, Left, Width, Height, Text, and whatever other properties you're interested in.

You would have to walk the object graph that is your form and it's child controls, and their child controls, adding data objects to your data structure representing each control. Once you've built your data structure, you can then serialize that structure to an XML file.

Rebuilding the form is the opposite. You read back the XML file, deserializing it back into your data structure. You then walk your data structure, creating the controls and setting their properties based on the data you have in the structure.

No, I don't have an example.
 
Share this answer
 
If you create a Form with the Designer all the data, which is needed to re-create the Form is stored (automaticly by the Designer) inside the Designer-Script from the Form (for example : 'Form2.Designer.vb'). This Script is contains a Standard-VB.Net-Method (called 'InitializeComponent').This Method hold all the Settings which are required to build the Form.
What you have to do now is, if you want to create a/this Form dynamicly is :
- instance the required Controls (like it is done in the Designer-Script)
- make the needed Settings for the Controls - this means the Location, perhaps you like to have a different Font, perhaps the Color-Settings and so on

Of course you could store this Information inside a XML-File (or any other Format you like). To do it like this could be useful if some of the Properties could be changed by the User. If the Settings are fixed (not changeable) you could also do it with the Method which you allready have to create the Form.

I also don't have an example for this ... :(
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900