Show message via Save dialog in C #
SaveFileDialog savefileDialog1 = new SaveFileDialog();
DialogResult result = savefileDialog1.ShowDialog();
switch(result == DialogResult.OK)
case true:
//do something
case false:
MessageBox.Show("are you sure?","",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
How to show a message box through the saveialog window after clicking Cancel in the SaveDialog field, that is, the Save dialog box must be present in the background.
source to share
If the reason you want the "Cancel Save File Dialog" message box is because you close everything with unsaved changes, I suggest placing a call to the "Save File" dialog in a loop that continues until the flag is set. to stop the loop and bring up a message box if you don't get OK as a result. For example:
// lead-up code
SaveFileDialog sft = new SaveFileDialog();
BOOL bDone;
do
{
if (DialogResult.OK == sft.ShowDialog())
bDone = true;
else
{
DialogResult result = MessageBox.Show("Are you sure you don't want to save the changed file?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
bDone = (result == Yes) ? true : false;
}
} while (!bDone);
// carry on
This way, the save file dialog behaves consistently with how it works in other Windows applications, and you can let the user save the file (s) again if they accidentally hit "Cancel" in the Save File dialog box.
source to share
I'll have the second lubos. Unable to execute SaveFileDialog class.
What you basically want to do is capture the specific button click event on the SaveFileDialog, an event that the class doesn't provide you with. The solution, if you really want this functionality, is to flip your own save dialog so that you can handle each button however you want.
source to share
As far as I know, you cannot accomplish what you want in pure .Net using SaveFileDialog. You can probably execute it if you log out to Windows and listen to the actual messages on Windows and respond to a click event message etc. I prefer to avoid this.
You can search for a third party dialog class or write your own.
source to share
You can do it with some modification:
private void Form1_Load(object sender, EventArgs e)
{
DialogResult result = showDialog();
if (result == DialogResult.OK)
{
//Ok
}
else
{
DialogResult r = MessageBox.Show("Are you sure?", "Sure?", MessageBoxButtons.YesNo);
if(r.ToString()=="No")
{
showDialog();
}
}
}
public DialogResult showDialog()
{
SaveFileDialog savefileDialog1 = new SaveFileDialog();
DialogResult result = savefileDialog1.ShowDialog();
return result;
}
source to share