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
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
后弹出的对话框界面如下: