如果在我的SaveAs点击事件中,SaveFileDialog被Cancel取消,我希望我的formClosing事件可以cancel它的关闭操作。
void exitToolStripMenuItem_Click (object sender, EventArgs e) {
this.Close ();
}
void form1_FormClosing (object sender, FormClosingEventArgs e)
{
if (isContentChanged)
{
DialogResult result = MessageBox.Show ("Do you want to save [ "+this.Text+"] ?", "Save", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
saveAsToolStripMenuItem_Click (sender, e);
}
else if (result == DialogResult.Cancel)
e.Cancel = true;
}
}
private void saveAsToolStripMenuItem_Click (object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog ();
sfd.Filter = "Drawing Files | *.drg";
DialogResult result = sfd.ShowDialog ();
if (result == DialogResult.OK) {
SaveFile (sfd.FileName);
isContentChanged = false;
}
else if (result == DialogResult.Cancel)
{
// NEED TO CANCEL FORM CLOSING HERE
}
}
这是否可能?如果是,如何实现?
return;
来取消事件。 - Fᴀʀʜᴀɴ Aɴᴀᴍ