代码如下:

 

 1  private void btnOpenFileDialog_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog oFD = new OpenFileDialog();
 4             oFD.Title = "打开文件";
 5             oFD.ShowHelp = true;
 6             oFD.Filter = "文本文件|*.txt|RTF文件|*.rtf|所有文件|*.*";//过滤格式
 7             oFD.FilterIndex = 1;                                    //格式索引
 8             oFD.RestoreDirectory = false;
 9             oFD.InitialDirectory = "c:\\";                          //默认路径
10             oFD.Multiselect = true;                                 //是否多选
11             if (oFD.ShowDialog() == DialogResult.OK)
12             {
13                 MessageBox.Show(oFD.FileName);
14                 MessageBox.Show(oFD.FileNames[0]);
15                 MessageBox.Show(oFD.SafeFileName);
16                 MessageBox.Show(oFD.SafeFileNames[0]);
17             }
18 
19         }

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-12-22
猜你喜欢
  • 2021-12-23
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
相关资源
相似解决方案