winform openFileDialog的使用。

代码如下:

 

View Code
 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         }

 

posted on 2011-07-26 11:01  wtq  阅读(7844)  评论(1编辑  收藏  举报