c#中如何在文本框中显示txt文档

来源:百度知道 编辑:UC知道 时间:2024/05/28 02:42:54
txt文档中有多条内容,现在做到的是能够显示文档中的所有内容,但是不能够逐条显示,我的程序如写:
private void btnReadTxtStr_Click(object sender, EventArgs e)
{
using (StreamReader sr = new StreamReader("C:\\temp.txt", System.Text.Encoding.Default))
{
string TextStr;
TextStr = sr.ReadToEnd().ToString();
sr.Close();
this.txtReadTxtStr.Text = TextStr;
}
但不知道如何改动?

(1)在Visual Studio 中新建一个“Windows窗体应用程序”项目

(2)在Form1上布置一个TextBox 并将Multiline属性设置为true;ScrollBars属性设置为both

(3)窗体代码Form1.cs

using System;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
     &n