saving forms as XML

  • Thread starter Thread starter halex2000
  • Start date Start date
H

halex2000

Hi all, I would like to know if there is a way to save a form (and I mean
its definition, not the contents of its controls) to a XML file that can
then be loaded and showed at run time. In more general terms, I would like
to know if there is a way (a language or something like that) that makes it
possible to create/modify forms that will then be showed to the user.
Hope to have been clear enaugh...
Thank you for your help,
Alessandro
 
halex2000 said:
Hi all, I would like to know if there is a way to save a form (and I mean
its definition, not the contents of its controls) to a XML file that can
then be loaded and showed at run time. In more general terms, I would like
to know if there is a way (a language or something like that) that makes
it possible to create/modify forms that will then be showed to the user.
Hope to have been clear enaugh...

There isn't something "automatic", but you could do it with a relatively
small amount of code. To save the form definition as XML, you could iterate
over the Controls collection of the form and save the characteristics of
each control either directly as XML, or in a class defined by you and then
serialize that class. You will need a recursive routine for this purpose,
since the controls could be nested inside other controls.
In order to recover the XML file and show the form to the user, you
would have to read the xml, and then iterate through it, create the controls
that it defines, set their properties, and add them to the appropriate
Controls collection.
If you want it completely generic, so that it supports every possible
kind of Control without having to handle all of them in a large switch
construct, you could use Reflection to save and recreate the controls and
their properties. All in all, it seems like this would be a pretty neat
utility class to have around. Maybe someone has already written and
published something like this?
 
Alberto Poblacion said:
There isn't something "automatic", but you could do it with a
relatively small amount of code. To save the form definition as XML, you
could iterate over the Controls collection of the form and save the
characteristics of each control either directly as XML, or in a class
defined by you and then serialize that class. You will need a recursive
routine for this purpose, since the controls could be nested inside other
controls.
In order to recover the XML file and show the form to the user, you
would have to read the xml, and then iterate through it, create the
controls that it defines, set their properties, and add them to the
appropriate Controls collection.
If you want it completely generic, so that it supports every possible
kind of Control without having to handle all of them in a large switch
construct, you could use Reflection to save and recreate the controls and
their properties. All in all, it seems like this would be a pretty neat
utility class to have around. Maybe someone has already written and
published something like this?

Thank you, I was thinking something similar as well. The pourpose of this
all is to have some kind of scripting system to interact with the app and
with a database, and for the forms we were thinking to this. Do you think
there are better ways? For Example, are there scripting language available
for use withing C# apps that provide GUI and DB connection capabilities?
 

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

Back
Top