private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "文本文件 txt|*.txt";
if (openDlg.ShowDialog() == DialogResult.OK)
{
string openFileName = openDlg.FileName;
System.IO.StreamReader sr = new System.IO.StreamReader(openFileName,System.Text.Encoding.Default);//第二个参数防止中文乱码
this.textBox1.Text = sr.ReadToEnd();
sr.Close();
}
} |