CodeSmith实用技巧(三):使用FileDialogAttribute

  使用FileDialogAttribute可以设置FileNameEditor中的属性,基本成员如下:

属性

描述

默认值

FileDialogType

Save or Open

FileDialogType.Save

Filter

Filter string for file extensions

All Files (*.*)|*.*

Title

Dialog box title

Select propertyname

DefaultExtension

Default file extensions

None

CheckFileExists

True to only allow selecting existing files

False

CheckPathExists

True to only allow using existing paths

False

在下面这段模版代码中,我们设置了弹出的对话框的类型为打开文件对话框,标题为“Select Input File”。

 1private string _openFileName = @"c:\temp\test.txt";
 2[Editor(typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor)),
 3FileDialogAttribute(FileDialogType.Open, Title="Select Input File"),
 4Category("Custom"), Description("User selected file.")]
 5public string OpenFileName
 6{
 7      get {return _openFileName;}
 8      set {_openFileName= value;}
 9}

10
11执行
12

后弹出的对话框界面如下:

posted @   TerryLee  阅读(4595)  评论(1编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示