How to do something if you click the cancel button on the file save dialog?

I am using C # WinForms. After that, a save dialog box and a message box appear stating that it was saved successfully.

I just realized that if the user clicks the Cancel button, my message box still arrives.

How can I say when the user clicks the cancel button in the save dialog and then does something when canceled?

+6
source share
2 answers

The save dialog after closing has the DialogResult property set to what happens. In your case:

if (mySaveDialog.DialogResult == DialogResult.OK) { /* show saved ok */ } 
+12
source

Use DialogResult

 if (form.ShowDialog() == DialogResult.Cancel) { //user cancelled out } 

For SaveFileDialog :

 SaveFileDialog saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == DialogResult.OK) { MessageBox.Show("your Message"); } 
+13
source

Source: https://habr.com/ru/post/974900/


All Articles