private void ButtonAddNew_Click(object sender, EventArgs e) //event to add a new student { frmAddNewStudent newStudentForm = new frmAddNewStudent(); //declare instance of a new form frmAddNewStudent newStudentForm.Show(); //show the form this.Hide(); newStudentForm.VisibleChanged += formVisibleChanged; //change visibility }
private void formVisibleChanged(object sender, EventArgs e) // method for when frmAddNewStudent closes { frmAddNewStudent newStudentForm = (frmAddNewStudent)sender; //instance of frmAddNewStudent if (!newStudentForm.Visible & newStudentForm.DoAddStudent()) //if form is not visible and DoAddStudent is true { students.Add(newStudentForm.returnStudent()); //add new student from form to students list FillStudentListBox(); //call method to add new student to the list box newStudentForm.Dispose(); //delete the old form this.Show(); //show } }