// save == true, если нужно сохранить матрицу кнопок private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // если форма не открыта -- вызвать её if (FormClose.open) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream("settimgs.txt", FileMode.OpenOrCreate)) { if (save) { SaveSetAndRez saveS_R = new SaveSetAndRez(statistiks, supMatrix, true); formatter.Serialize(fs, saveS_R); } else { if (selectedBatton != radioButtonOption.Special) { statistiks.massAllTimeData[(int)selectedBatton, 0]++; statistiks.massCurrentTimeData[(int)selectedBatton, 0]++; } SaveSetAndRez saveS_R = new SaveSetAndRez(statistiks, supMatrix); formatter.Serialize(fs, saveS_R); } } } else { e.Cancel = true; if (startGame) { FormClose closeForm = new FormClose(this); closeForm.Show(); } else { FormClose.open = true; Close(); } } }
public Form1() { InitializeComponent(); try { Stream file = File.OpenRead("settimgs.txt"); BinaryFormatter fileRead = new BinaryFormatter(); SaveSetAndRez saveS_R = (SaveSetAndRez)fileRead.Deserialize(file); file.Close(); statistiks = new StatisticsData(); statistiks.massAllTimeData = saveS_R.Statistics; selectedBatton = saveS_R.selectedBatton; supMatrix = saveS_R.createMatrixSapperButton(this); } catch { supMatrix = new MatrixSapperButton(this, 16, 16, 40); // соответствует Medium selectedBatton = radioButtonOption.Medium; statistiks = new StatisticsData(); } supMatrix.AddMatrixSapperButtonOnForm(); }