I have modified the code for the yes result of the dialog box so that instead of saving to a hard coded test.rtf file, it shows the save as dialog.
I used the code that i used for the Save As menu option.
I have a problem though. The dialog shows ok if I want to save the modifications, I click yes and it shows the save as dialog box, however, if after showing the dialog box i click cancel, it crashes. It has an error
ArgumentException was unhandled - Empty pathname is not legal. Below is the code i am using. The red text is the line where the error crashes to.
Code:
private void SimpleEditForm_FormClosing(object sender, FormClosingEventArgs e)
{
//decides whether to continue with the operation
bool shouldContinue;
// Check for unsaved changes.
if (contentRichTextBox.Modified)
{
// Ask the user if we should save the changes.
DialogResult result =
MessageBox.Show(
"There are unsaved changes.\n" +
"Do you want to save the changes?",
"Save Changes?",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
// See if we should save the changes.
if (result == DialogResult.Yes)
{
// Save the changes.
saveFileDialog1.ShowDialog();
contentRichTextBox.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText);
openFileDialog1.FilterIndex = saveFileDialog1.FilterIndex;
// It's now safe to continue.
shouldContinue = true;
}
else if (result == DialogResult.No)
{
// continue and discard the changes.
shouldContinue = true;
}
else
{
// The user wants to cancel.
// Don't continue.
shouldContinue = false;
}
}
else
{
// No unsaved changes so it's safe to continue.
shouldContinue = true;
}
// See if it's safe to continue.
e.Cancel = (!shouldContinue);
}
I figure that it means that it wants a filename, but why when i cancel the save as dialog isnt it just cancelling? Is it because its still part of the save modifications dialog box? Do i need a new 'if' statement to cover the save as dialog?