1

In my WinForms C# Application I am attempting to save a custom class in a settings file. here is my current code:

public class PanelSaver : ApplicationSettingsBase
{
  private DockingStyle ds;
  System.Drawing.Point location;
  System.Drawing.Size panelSize;

  [UserScopedSetting()]
  [SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Xml)]
  public DockingStyle Style
  {
     get { return ds; }
     set { ds = value; }
  }
  public System.Drawing.Point Location
  {
     get { return location; }
     set { location = value; }
  }
  public System.Drawing.Size Size
  {
     get { return panelSize; }
     set { panelSize = value; }
  }
}

The DockingStyle variable comes from DevExpress Dockpanels.

Here are the objects being used in the Settings file :

enter image description here

When I attempt to use these variables, by passing them into this function:

private void DockPanelSave(PanelSaver savingPanel, DockPanel realDockingPanel)//
{
   try
   {
      savingPanel.Location = realDockingPanel.Location;
      savingPanel.Size = realDockingPanel.Size;
      savingPanel.Style = realDockingPanel.Dock;
   }
   catch (Exception e)
   {
      MessageBox.Show(e.Message);
      throw new NotSupportedException("You may have added a new panel, and may not have added a corresponding " +
      "settings variable to hold it in the Settings.settings file");
   }

}

I get a null error.

How should I initialize the values in the settings file? I am guessing I need to put in some kind of XML however I don't know the correct steps to take for generating it. Any directions on this or other reasons for my null error would be appreciated

Lex Li
  • 60,503
  • 9
  • 116
  • 147
jth41
  • 3,808
  • 9
  • 59
  • 109

1 Answers1

-2

You can see by this answer I show how to do what you are asking.

It isn't the built in serialization, but you can define your class by my example and get the same result.

Here's another example,

and another

Community
  • 1
  • 1
Chuck Savage
  • 11,775
  • 6
  • 49
  • 69