I have an assembly that contains several UserControl objects that I want to save / load through the user interface of the application. To do this, each control implements the ISerializable interface to configure the fields that must be saved.
Here is a simplified version of this library:
namespace LibraryProject { using System; using System.Runtime.Serialization; using System.Windows.Forms; [Serializable] public partial class UserControl1 : UserControl, ISerializable { public UserControl1() { InitializeComponent(); } public UserControl1(SerializationInfo info, StreamingContext ctxt) : this() { this.checkBox1.Checked = info.GetBoolean("Checked"); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Checked", this.checkBox1.Checked); } } }
The client application creates several of these controls and allows the user to save / load various UserControl configurations. Here is a simplified version of the application:
namespace ApplicationProject { using System; using System.IO; using System.Runtime.Serialization.Formatters.Soap; using System.Windows.Forms; using LibraryProject; public partial class Form1 : Form { private const string filename = @"test.xml";
In SaveClick values โโare saved in a file. In LoadClick the CheckBox.Checked parameter is properly updated in the debug view list, but the user interface does not reflect the new value.
I tried adding calls to Refresh() , Invalidate() , Update() , but nothing works.
As expected, hash1 and hash2 are different, but Form1 uses the correct instance.
What am I doing wrong, and how can I fix the user interface to display the correct (updated) value?
EDIT: Also note that I need to process multiple configuration files so that the user can save / load / delete the path of their choice.