/// <summary> /// Load the state.bin with data from previous runs /// of the program, if there is one /// </summary> private void loadState() { SaveLoad tmpLoader = new SaveLoad(); SaveFile tmpLoadFile = tmpLoader.LoadState(); ///If the tmpFile.Math == null, there was no successfull load ///of the bin-file if (tmpLoadFile.Math != null) { ///Load all fields with data from tmpFile mathEngine = tmpLoadFile.Math; oldNumber = tmpLoadFile.OldNumber; newNumber = tmpLoadFile.NewNumber; firstNumberEntered = tmpLoadFile.FirstNumberEntered; resultInTextbox = tmpLoadFile.ResultInTextbox; calcButtonClicked = tmpLoadFile.CalcButtonClicked; calculationSign = tmpLoadFile.CalculationSign; currentCalculation = tmpLoadFile.CurrentCalculation; currentInput = tmpLoadFile.CurrentInput; previousCalculations = tmpLoadFile.PreviousCalculations; ///Put the history to the listBox foreach(History tmpHistory in previousCalculations) { lstHistory.Items.Add(tmpHistory); } ///Update updateCalculationTextBox(); updateInputTextBox(); } }
/// <summary> /// Save the current state of the program when the form is closed /// </summary> private void saveState() { SaveFile tmpSaveFile = new SaveFile(mathEngine, oldNumber, newNumber, firstNumberEntered, resultInTextbox, calcButtonClicked, calculationSign, currentCalculation, currentInput, previousCalculations); SaveLoad tmpSaver = new SaveLoad(); tmpSaver.SaveState(tmpSaveFile); }