Search code examples
c#data-bindingproperties.settings

Save/Read object values using Properties.Settings


I want to save the state of my object when the software exit and restore it when the software loads. Im doing this (code below) now, but I think there must be another bether/smarter way to do that. :) Ive read a little about Databing, but for this I would need to modify MyClass, deriving it from CollectionBase, etc.. Do you think it is a good ideia? One more thing, is there a way to store a Point*F* (PointFFFF no Point) directly in Properties.Settings (I could not find it in browse)?

LoadConfig()
{
    MyClass.ItemA = Properties.Settings.Default.ItemA;
}
SaveConfig()
{
    Properties.Settings.Default.ItemA = MyClass.ItemA;
    Settings.Default.Save();
}

Solution

  • I see nothing wrong with it. Yes, you could certainly use bindings also. You can create settings for other non-primitive types by going to type "Browse..." and then select the type you want to save. You would be able to browse for System.Drawing.Point and use that. It'll serialize the value in the app.config file.

    enter image description here