Search code examples
c#opendialog

How to know user close open dialog without saving?


SaveFileDialog sfd = new SaveFileDialog();

sfd.ShowDialog();
sfd.Filter("Wave Files|*.wav");
ss.SetOutPutToWaveFile(sfd.FileName);
ss.Speak(richTextbox.Text);
ss.SetOutputToDefaultAudioDevice();

Solution

  • Use a return value from sfd.ShowDialog():

    if (sfd.ShowDialog() == DialogResult.OK)
    {
        // File was selected
    }
    else
    {
        // Cancelled
    }