Hi,
I have a number NumericUpDown controls that I wish to save their settings.
I create a resource file and save them by foreach loop with Type (NumericUpDown) condition.
I then iterate through the file to read back and set the values into the controls.
Unfortunately, I am probably doing something wrong, as I do not get the values back into the controls.
1. The resource file is written, and looks OK (Using a hex editor).
2. Saving and reading the resource file manually (one-by-one, no foreach) works OK.
3. Seems as if the issue is with reading and loading into the controls.
Can someone help me out?
Thanks, Sam
Here is a simplified stripped code example :
(To run, build a form with 3 generic numericUpDown (1,2,3) controls and two buttons: buttonSave and buttonLoad)
using System.Windows.Forms; using System.Resources; using System.Collections; namespace ResourceFile { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void saveToFile() { ResourceWriter rw = new ResourceWriter(@"C:\Temp\MyFile.resources"); foreach (Control resource in Controls) { if (resource.GetType() == typeof(NumericUpDown)) { rw.AddResource(resource.Name, resource.Text); } } rw.Generate(); rw.Close(); } private void loadFromFile() { ResourceSet rs = new ResourceSet(@"C:\Temp\MyFile.resources"); foreach (DictionaryEntry resource in rs) { rs.GetObject(resource.Key.ToString()); } rs.Close(); } private void buttonSave_Click(object sender, System.EventArgs e) { saveToFile(); } private void buttonLoad_Click(object sender, System.EventArgs e) { loadFromFile(); } } }
|