/// <summary> /// Constructor for opening spreadsheet. /// </summary> /// <param name="window"></param> /// <param name="filename"></param> public Controller(SpreadsheetView window, String filename) : this(window) { TextReader openfile = null; try { ssModule = new Spreadsheet(openfile = File.OpenText(filename), new Regex("^[a-zA-Z]{1}[1-9]{1}[0-9]?$")); window.NewEvent += HandleNew; DrawFromFile(); } catch { MessageBox.Show("Error occured when trying to open file."); } }
/// <summary> /// Constructor contollor for when a new/blank spreadsheet is added. /// </summary> /// <param name="window"></param> public Controller(SpreadsheetView window) { this.window = window; ssModule = new Spreadsheet(new Regex("^[a-zA-Z]{1}[1-9]{1}[0-9]?$")); window.NewEvent += HandleNew; window.FileChosenEvent += HandleFileChosen; window.CloseEvent += HandleClose; window.SelectionEvent += HandleChange; window.UpdateEvent += HandleUpdate; window.SaveEvent += HandleSave; }
/// <summary> /// Runs a form in this application context /// </summary> public void RunNew(Spreadsheet ss) { // Create the window and the controller SpreadsheetView window = new SpreadsheetView(); new Controller(window, ss); // One more form is running windowCount++; // When this form closes, we want to find out window.FormClosed += (o, e) => { if (--windowCount <= 0) { ExitThread(); } }; // Run the form window.Show(); }