我有一个属性网格控件,我希望能够在用户将数据导出到新文件的过程中显示 SaveFileDialog。我可以轻松地将 OpenFileDialog 与 FileNameEditor 连接起来,但似乎没有用于保存文件的等效类。
是否存在可以在 System.ComponentModel.Editor 属性中指定的现有类,以便显示 SaveFileDialog?
这工作正常:
public class SaveFileNameEditor: UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (context == null || context.Instance == null || provider == null)
{
return base.EditValue(context, provider, value);
}
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
if (value != null)
{
saveFileDialog.FileName = value.ToString();
}
saveFileDialog.Title = context.PropertyDescriptor.DisplayName;
saveFileDialog.Filter = "All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
value = saveFileDialog.FileName;
}
}
return value;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)