做了个记事本,打开文件时,遇到中文就乱码
我做了一个记事本,打开文件时,中文的地方显示的就是乱码,而字母和数字不会.以下是打开文件的代码:
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "文本文档(*.txt)|*.txt|" + "所有文件(*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFileDialog1.FileName);
txtBody.Text = sr.ReadToEnd();
MessageBox.Show(txtBody.Text);
sr.Close();
this.Text = "NotePad_C_Sharp - "+openFileDialog1.FileName;
}
}