"halex2000" <po*******@libero.itwrote in message
news:RO********************@twister2.libero.it...
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?