Example #1
0
        public void Save(MainForm form, string fileName)
        {
            MainFormSettingsValues values = form.Settings;

            using( Stream stream = new FileStream(@fileName, FileMode.Create) )
            {
                // Write to the stream
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, values);
            }
        }
Example #2
0
        public MainFormSettingsValues Load(MainForm form, string fileName)
        {
            MainFormSettingsValues values;
            try
            {
                using( Stream stream = new FileStream(@fileName, FileMode.OpenOrCreate) )
                {
                    IFormatter formatter = new BinaryFormatter();
                    values = (MainFormSettingsValues)formatter.Deserialize(stream);
                }
            }
            catch(Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "Loadsettings exception");
                values = new MainFormSettingsValues();
            }

            form.StartPosition = FormStartPosition.Manual;

            return values;
        }