public void button2_Click(object sender, EventArgs e) { if (text != null) { AddCourse newCourse = new AddCourse(text, listBox1, names); newCourse.Show(); } else { MessageBox.Show("A file was not opened", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }