private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
foreach (TabPage t in tabControl1.TabPages)
{
int i = tabControl1.TabPages.IndexOf(t);
if (unsaved[i])
{
DialogResult result = MessageBox.Show("Your script \"" + t.Text + "\" is unsaved. Would you like to save it before closing?",
"Save?",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
switch (result)
{
case DialogResult.Yes:
result = saveFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
try
{
File.WriteAllLines(saveFileDialog1.FileName, scripts[tabControl1.SelectedIndex].Lines.ToArray());
}
catch
{
MessageBox.Show("The file could not be saved. This programme will be kept open.");
e.Cancel = true;
}
}
else
{
MessageBox.Show("The file could not be saved. This programme will be kept open.");
e.Cancel = true;
}
break;
case DialogResult.No:
break;
default:
e.Cancel = true;
break;
}
}
}
}