实现效果:
知识运用:
StreamReader类的ReadLine方法 //从当前流中读取一行字符并将数据作为字符串返回
public override string ReadLine ()
实现代码:
private void button1_Click(object sender, EventArgs e) { try { OpenFileDialog open = new OpenFileDialog(); open.Filter = "文本文件(*.txt)|*.txt"; open.ShowDialog(); textBox1.Text = open.FileName; StreamReader sr = new StreamReader(textBox1.Text, Encoding.UTF8); label3.Text = sr.ReadLine(); sr.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }