c#保存文件时候的弹出选择要保存的文件夹带新建文件夹效果的类代码

添加引用system.design.dll

//选择文件的保存路径
   DirBrowser   olderBrowserDlg=new   DirBrowser();  
   
   if (folderBrowserDlg.ShowDialog()==DialogResult.OK)
   {
    txtFilePath.Text = folderBrowserDlg.SelectedPath;
   }

//

using System.Windows.Forms.Design;
using System.Windows.Forms;
using System;
 

//一般选择文件保存地址都用弹出对话框来进行选择
public class DirectorySelect : FolderNameEditor
{
 private FolderBrowser fb = new FolderBrowser();
 private string fDescription = "Choose Directory";
 private string fReturnPath = String.Empty;
 
 public string Description
 {
  set { fDescription = value; }
  get { return fDescription; }
 }
 
 public string ReturnPath
 {
  get { return fReturnPath; }
 }
 
 public DirectorySelect()
 {
 
 }
 
 private DialogResult RunDialog()
 {
  fb.Description = this.Description;
  fb.StartLocation = FolderBrowserFolder.MyComputer;
  fb.Style = FolderBrowserStyles.RestrictToSubfolders;
  //|FolderBrowserStyles.RestrictToDomain;
  return fb.ShowDialog();
 }
 
 public DialogResult ShowDialog()
 {
  DialogResult dRes = DialogResult.None;
  dRes = RunDialog();
  if (dRes == DialogResult.OK)
   this.fReturnPath = fb.DirectoryPath;
  else
   this.fReturnPath = String.Empty;
  return dRes;
 }
}

//一般选择文件保存地址都用弹出对话框来进行选择
//调用  
//DirBrowser   myDirBrowser=new   DirBrowser();  
//if(myDirBrowser.ShowDialog()!=DialogResult.Cancel)  
//MessageBox.Show(myDirBrowser.ReturnPath);  

public   class   DirBrowser   :   FolderNameEditor    
{    
 FolderBrowser   fb   =   new   FolderBrowser();    
 public   string   Description    
 {    
  set   {   _description   =   value;   }    
  get   {   return   _description;   }    
 }    
     
 public   string   ReturnPath    
 {    
  get   {   return   _returnPath;   }    
 }    
     
 public   DirBrowser()   {   }    
 public   DialogResult   ShowDialog()    
 {    
  fb.Description   =   _description;    
  fb.StartLocation   =   FolderBrowserFolder.MyComputer;    
  DialogResult   r   =   fb.ShowDialog();    
  if   (r   ==   DialogResult.OK)    
   _returnPath   =   fb.DirectoryPath;    
  else    
   _returnPath   =   String.Empty;    
     
  return   r;    
 }    
   
 //private   string   _description   =   "Choose   Directory";    
 //private   string   _returnPath   =   String.Empty; 
 private   string   _description   =   "请选择文件夹";    
 private   string   _returnPath   =   String.Empty; 
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值