DialogResult.OK on SaveFileDialog not work(SaveFileDialog 上的 DialogResult.OK 不起作用)
问题描述
我尝试,当我在 SaveFileDialog 中按保存时,我会做一些事情.我尝试修复,但总是有问题.
I try, when I press save in SaveFileDialog I do something. I trying fix but always something wrong.
SaveFileDialog dlg2 = new SaveFileDialog();
dlg2.Filter = "xml | *.xml";
dlg2.DefaultExt = "xml";
dlg2.ShowDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
{....}
但我在 OK 上有错误 - 说:
But I have error on OK - which say:
错误:System.Nullable"不包含OK"的定义,并且找不到接受System.Nullable"类型的第一个参数的扩展方法OK"(您是否缺少 using 指令或程序集引用?)
我尝试用这段代码修复:
I try fix with this code:
DialogResult result = dlg2.ShowDialog(); //here is error again
if (result == DialogResult.OK)
{....}
现在错误出现在 DialogResult 上说:'System.Windows.Window.DialogResult' 是一个 'property' 但被用作一个 'type'
Now error is on DialogResult say: 'System.Windows.Window.DialogResult' is a 'property' but is used like a 'type'
推荐答案
我假设你指的是 WPF 而不是 Windows Form这是使用 SaveFileDialog
I assume that you are referring to WPF not Windows Form
Here is example of using SaveFileDialog
//configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; //default file name
dlg.DefaultExt = ".xml"; //default file extension
dlg.Filter = "XML documents (.xml)|*.xml"; //filter files by extension
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
}
其他示例:
在 WPF 中你必须处理 DialogResult 枚举和 Window.DialogResult 属性之间的冲突
In WPF you have to handle conflict between DialogResult Enumeration and Window.DialogResult Property
尝试使用完全限定名称来引用枚举:
Try using fully qualified name to refer the enumeration:
System.Windows.Forms.DialogResult result = dlg2.ShowDialog();
if (result == DialogResult.OK)
{....}
这篇关于SaveFileDialog 上的 DialogResult.OK 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SaveFileDialog 上的 DialogResult.OK 不起作用
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
