private System.Windows.Forms.OpenFileDialog openFileDialog1;
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
// 
// openFileDialog1
// 
this.openFileDialog1.Filter = "Text Files (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf|All Files (*.*)|*.*";
this.openFileDialog1.RestoreDirectory = true;
this.openFileDialog1.Title = "打开一个文件";
/// <summary>
/// 打开文件的方法
/// </summary>
public void openfile()
{
StreamReader sr = null;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
 try
   {
//使用文件名构建文本读取流
sr = new StreamReader(openFileDialog1.FileName,System.Text.Encoding.Default);
richTextBox1.Text = sr.ReadToEnd();
    }
catch(Exception excep)
{
MessageBox.Show(excep.Message,"err");
}
finally
{
             if(sr != null)
{
//close
sr.Close();
}
     }
}
}