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

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

作者:TerryLee
出处:http://terrylee.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted @ 2005-12-27 13:32 TerryLee 阅读(1675) 评论(1)  编辑 收藏 所属分类: CodeSmith

  回复  引用  查看    
#1楼 2005-12-28 15:07 | kid_li      
我试了一下Filter,挺好用
[Editor(typeof(CodeSmith.CustomProperties.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor)),
FileDialogAttribute(FileDialogType.Open,Filter="(*.txt)|*.txt",Title="Select Input File"),
Category("Custom"), Description("User selected file.")]

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2005-12-28 08:29 编辑过