我尝试,当我按下“保存”时SaveFileDialog
我做某事。我尝试修复但总是出错。
SaveFileDialog dlg2 = new SaveFileDialog();
dlg2.Filter = "xml | *.xml";
dlg2.DefaultExt = "xml";
dlg2.ShowDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
{....}
但我在 OK 上有错误 - 上面写着:
Error:
“System.Nullable”不包含“OK”的定义,并且找不到接受“System.Nullable”类型的第一个参数的扩展方法“OK”(您是否缺少 using 指令或程序集引用?)
我尝试用这段代码修复:
DialogResult result = dlg2.ShowDialog(); //here is error again
if (result == DialogResult.OK)
{....}
现在 DialogResult 上出现错误:“System.Windows.Window.DialogResult”是一个“属性”,但像“类型”一样使用
我假设你指的是WPF
not Windows Form
这是使用的示例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;
}
其他例子:
In WPF
你必须处理之间的冲突DialogResult
枚举和Window.DialogResult
财产
尝试使用完全限定名称来引用枚举:
System.Windows.Forms.DialogResult result = dlg2.ShowDialog();
if (result == DialogResult.OK)
{....}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)