C#winform打开文件夹选择器

一、打开文件夹选择器 

 System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
 dialog.Description = "请选择文件夹";
 if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
 {
    if (string.IsNullOrEmpty(dialog.SelectedPath))
    {
      MessageBox.Show( "文件夹路径不能为空", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
      return;
    }
    textBox.Text = dialog.SelectedPath + "\\";
    //do something
}

 

二、打开文件选择器

  OpenFileDialog dialog = new OpenFileDialog();
  dialog.Multiselect = false;//该值确定是否可以选择多个文件
  dialog.Title = "请选择文件夹";
  dialog.Filter = "所有文件(*.*)|*.*";
  if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    textBox.Text = dialog.FileName;    
    // do something           
  }

 

你可能感兴趣的:(随笔,备忘,C#,winform)