private void button5_Click(object sender, EventArgs e) { try { if (listBox2.SelectedIndex < 0) throw new FormatException(); string s = listBox2.Items[listBox2.SelectedIndex].ToString(); int p = FindP(s); int n = FindN(s); Parser pars = new Parser(); StreamReader sr = new StreamReader("Special Polinoms.txt"); cpolinom pol = new cpolinom("", p); while (sr.EndOfStream == false) { string str = sr.ReadLine(); pol = pars.ParseString(str); if (pol.mod == p && pol.Count - 1 == n) break; } sr.Close(); StreamWriter w = new StreamWriter(p.ToString() + "," + n.ToString() + ".txt"); pol.PrintPolinom(w); w.Close(); System.Windows.Forms.MessageBox.Show("Done"); } catch (FormatException exc) { System.Windows.Forms.MessageBox.Show("Error"); } catch (IndexOutOfRangeException exc) { System.Windows.Forms.MessageBox.Show("Error"); } }