Winform选择目录路径与选择文件路径

来源:互联网 发布:日本眼药水 知乎 编辑:程序博客网 时间:2024/06/05 08:22
[csharp] view plain copy
print?
  1. using System.Collections.Generic;  
  2. using System.ComponentModel;  
  3. using System.Data;  
  4. using System.Drawing;  
  5. using System.Text;  
  6. using System.Windows.Forms;  
  7. namespace WindowsApplication1 {  
  8. public partial class SelectFolder: Form {  
  9. public SelectFolder()   
  10.   {  
  11.     InitializeComponent();  
  12.   }  
  13. private void btnSelectPath_Click(object sender, EventArgs e) //弹出一个选择目录的对话框  
  14.  {  
  15.     FolderBrowserDialog path = new FolderBrowserDialog();  
  16.     path.ShowDialog();  
  17.     this.txtPath.Text = path.SelectedPath;  
  18.  }  
  19. private void btnSelectFile_Click(object sender, EventArgs e) //弹出一个选择文件的对话框  
  20.  {  
  21.     OpenFileDialog file = new OpenFileDialog();  
  22.     file.ShowDialog();  
  23.     this.txtFile.Text = file.SafeFileName;  
  24.  }  
  25. }  
  26. }