views:

49

answers:

0

I have a panel to which button controls are added in runtime. The panel and all its contents should be saved in the user settings (Properties.Settings.Default.MyPanel). However, while the settings object does accept strings, ints, etc. as input and stores it correctly when calling the Settings.Default.Save() method, it doesn't when I'm storing a Panel object in the user settings.

Example:

public Form1() {
    panel1 = Settings.Default.MyPanel;
    s = Settings.Default.MyString;
}

public MethodThatDoesSomethingInterestingToPanelAndString() {
    // Here, some buttons are added to panel1, and String s is altered.
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    Settings.Default.MyPanel = panel1;
    Settings.Default.MyString = s;
    Settings.Default.Save();
}

Settings.Default.MyString get updated, while Settings.Default.MyPanel is null after restarting the application. In what way should I store user specific dynamic information?