Deleting and creating controls via code

J

John

Hi

Is it possible to enumerate all controls on a form and then save the info in
an xml file via code? Is it possible to reverse the process i.e. read info
from and xml and recreate all controls on a blank form? I am just trying to
find a way to cerate "templates" so users can choose which controls they
want to see and with what attributes; position, size, colour etc.

A code example would be great.

Many Thanks

Regards
 
B

Bob Powell [MVP]

Yeah sure, it's called XAML ;-)

But seriously...

The idea isn't new and there are several concrete ways of doing it but
there are some pitfalls.

Using the simplest method, that of XML serialisation, is impossible
without significant work because forms and other controls contain values
and objects that are themselves not serialisable.

The method best known is to use the Memento Pattern in which you create
a family of objects that are themselves perfectly serialisable and can
represent the graph of objects that you really want to save and load.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

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

Top