使用C#从文本文件中读取

Klu*_*key 1 c#

所以我正在制作一个聊天程序,但是我在文本框中创建一个新行而不是覆盖其他消息时遇到问题.这是我的代码:

        private void refreshRate_Tick(object sender, EventArgs e)
        {
        String ChatPath = @"Path";
        String line;
        try
        {
            StreamReader sr = new StreamReader(@"Path");
            line = sr.ReadLine();
            richTextBox1.Text = null;
            while (line != null)
            {
                richTextBox1.AppendText(Environment.NewLine);
                richTextBox1.Text = line;
                line = sr.ReadLine();
            }
            sr.Close();
        }
        catch (Exception r)
        {
            Console.WriteLine("Exception: " + r.Message);
        }
        finally
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

Ani*_*dha 5

你不需要StreamReaderEnvironment.NewLine

richTextBox1.Text=File.ReadAllText(path);
Run Code Online (Sandbox Code Playgroud)