SaveFileDialog 上的 DialogResult.OK 不起作用

13

本文介绍了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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14