所以我正在制作一个聊天程序,但我在文本框中创建一个新行而不是覆盖其他消息时遇到问题。这是我的代码:
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
{
}
}
最佳答案
您不需要StreamReader
或Environment.NewLine
richTextBox1.Text=File.ReadAllText(path);
关于c# - 使用 C# 从文本文件中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481333/