Below is my code. Whenever a user clicks cancel in the savedialog.showdialog() screen it still tries to save the zip file any help is appreciated!
Thanks,
Kyvex
If saveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.Cancel Then
Return
Else
zip.Save(zippath)
End If
Could try something like this? If its just a simple yes/no/cancel box?
Dim result As Integer = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel)
If result = DialogResult.Cancel Then
*whatever you want
ElseIf result = DialogResult.No Then
*whatever you want
ElseIf result = DialogResult.Yes Then
*whatever you want
End If
just seen it was a savefiledialog in that case do soemthing similar to this
If SaveFileDialog1.ShowDialog() = DialogResult.Ok
zip.Save(zippath)
Else
msgbox.show("Cancelled!")
End If
or another option may be
Select Case SaveFileDialog1.ShowDialog()
Case DialogResult.Ok
zip.Save(zippath)
Case DialogResult.Cancel
msgbox.show("Cancelled!")
End Select
Using the DialogResult.OK is more effective, because you will only write the file if you click "OK"
If SaveFileDialog.ShowDialog = DialogResult.OK Then
zip.Save(zippath)
Else
Return
End If
There are a few ways to cancel the save of the file, and in some of them, the dialog result is not "Cancel".
I appreciate all the help! But I did find the fix. What I did was set a variable to the saveFileDialog1.ShowDialog() like so
Dim tempvar = saveFileDialog1.ShowDialog()
Then I set a break point for when the DialogResult happens. When the user clicks cancel or the X in the top right corner it sets tempvar to false but if they click Save it sets it to true so below is the code I made up, and it works great!
If tempvar = False Then
Return
Else
zip.Save(zippath)
End If
I appreciate all the help guys! Thank you very much!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.