How to do something if cancel button on save file dialog was clicked?
Solution 1
A save dialog box after closing has the DialogResult property set to what happens. In your case:
if (mySaveDialog.DialogResult == DialogResult.OK) { /* show saved ok */ }
Solution 2
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");
}
jAC
During my day life, I am a technical manager make sure that our support staff has the resources they need to their jobs. I conduct application testing and providing assistance where ever possible. My side business is web development mainly. I started out a long time ago with PHP and now have moved on to Python/Django to fill those needs. I am a self taught programer and as my posts here show that, I still like to learn as much as i can while making these mistakes to learn from. Music is my other life. I am a drummer and like to learn new musical things as much as i do in programming.
Updated on June 15, 2022Comments
-
jAC almost 2 years
I am using c# WinForms. I have a save dialog box that pops up and a message box after that that says it was saved successfully.
I just realized that if a user clicks cancel, my message box still comes.
How do i tell when a user clicks the cancel button on a save dialog box and then do something when it is cancelled?