//opens an existing file when this button is clicked private void OpenWorkshop_Click(object sender, EventArgs e) { // create and show dialog box that enables user to open file OpenFileDialog fileChooser = new OpenFileDialog(); DialogResult result = fileChooser.ShowDialog(); WorkshopName name = new WorkshopName(); // exits the open event handler if user clicks Cancel if (result != DialogResult.Cancel) { try { fileName = fileChooser.FileName; // get name of file from user if (fileName.Contains(".sup") == false) // show error if the selected file is not a .sup file { MessageBox.Show("The file must be a .sup file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { WorkshopForm workshop = new WorkshopForm(fileName, name.WsName); //creates object of the workshopForm workshop.MdiParent = this; //makes this form the parent form of the display workshop form workshop.Show(); } } //exception when a file doesn't exist catch (FileNotFoundException) { //tells the user if file does not exist MessageBox.Show("This File does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void NewWorkshop_Click(object sender, EventArgs e) { WorkshopName name = new WorkshopName(); //creates object of the workshopName form name.ShowDialog(); //use showDialog because name is not a child of this Mdi if (fileName != "") { fileName += ".sup"; //makes the file a .sup file WorkshopForm workshop = new WorkshopForm(fileName, name.WsName); //creates object of the workshopForm workshop.MdiParent = this; //makes this form the parent form of the display workshop form workshop.Text = name.WsName; workshop.Show(); } }