1

I have built a form where the user can add controls, buttons and more dynamically.

is it possible somehow to save the dynamic controls and load them automatically the next time the user starts the program?

if it is not possible I would like to know if there is a common method or good practice for saving this data to some kind of a config file?

Thanks

  • 1
    You can iterate through all controls and save them in an XML file. Then, you can easily load this file and restore their locations \ sizes etc. – Yeldar Kurmangaliyev Jun 08 '15 at 06:21
  • The Windows Forms designer tends to inspire programmers to think "I can do that too!" Doesn't often turn out that well, they invariably hit the wall when it the non-trivial problems must be solved. Like persisting the design, there is nothing trivial about the way Winforms does this. A code generator gets that job done. [Read this](https://msdn.microsoft.com/en-us/magazine/cc163871.aspx) to get ahead. – Hans Passant Jun 08 '15 at 09:05

1 Answers1

0

One way would be to loop through all the controls on the form and save them to Isolated Storage...

https://msdn.microsoft.com/en-us/library/3ak841sy.aspx

https://msdn.microsoft.com/en-us/library/xf96a1wz(v=vs.110).aspx

But it really depends on your use case, do you want to do this automatically and transparent from the user, or do you want to present the user an option to save to a file somewhere?

While it is not specifically for dynamic controls, to give you more ideas see link below on another stackoverflow question :

Best practice to save application settings in a Windows Forms Application

Community
  • 1
  • 1
Xander
  • 1,123
  • 9
  • 14
  • I tried to read and check, and I'm not sure why Isolated Storage should be my choice? I can create my own file or XML. – user2367624 Jun 10 '15 at 13:56
  • Isolated Storage can be user specific, so different users could have different settings... Yes you could create your own file/xml but then you would have to worry about where to save the file and deal with permissions etc, this is what Isolated Storage is good for. – Xander Jul 13 '15 at 13:14