實現效果:
知識運用:
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); } }