我正在使用 SaveFileDialog 并想在允许保存文件之前评估文件是否满足某些条件。如果它不符合条件,我不希望 SaveFileDialog 在单击“保存”时关闭。我认为 FileOK 可能会起作用,但是在触发该事件时,对话框看起来已经关闭了,而且我看不到任何方法可以阻止它在任何情况下关闭。
问问题
1767 次
3 回答
3
FileOK
是CancelEventHandler
- 您只需将 的Cancel
属性设置CancelEventArgs
为true
。
于 2009-05-11T19:21:41.500 回答
3
从 FileOK 处理程序尝试这种方法
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
//your conditions...
if (!openFileDialog1.FileName.Equals( "C:\\hello.txt" ) )
{
//if fail, set e.cancel
MessageBox.Show(@"File name must equal c:\hello.txt.");
e.Cancel = true;
}
}
于 2009-05-11T19:29:32.733 回答
0
于 2009-05-11T19:20:24.560 回答