1 private void openFileDialogBTN_Click(object sender, System.EventArgs e){
2
3 OpenFileDialog openFileDialog=new OpenFileDialog();
4 openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\
5 openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";
6 openFileDialog.RestoreDirectory=true;
7 openFileDialog.FilterIndex=1;
8 if (openFileDialog.ShowDialog()==DialogResult.OK)
9 {
10 fName=openFileDialog.FileName;
11 File fileOpen=new File(fName);
12 isFileHaveName=true;
13 richTextBox1.Text=fileOpen.ReadFile();
14 richTextBox1.AppendText("");
15 }
16 }