TXT文档的循环遍历之后,怎么都是显示最后一行的呢?求解~
openFileDialog1.ShowDialog();
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
for (int i = 0; i < StrLine.Length; i++)
{
richTextBox1.Text = StrLine[i].ToString() + "\r\n";
}
------解决方案--------------------
richTextBox1.Text += StrLine[i].ToString() + "\r\n";
------解决方案--------------------
C# code
openFileDialog1.ShowDialog();
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
StringBuilder sb = new StringBuilder();
foreach( string str in StrLine)
{
sb.Append(str).Append("\r\n");
}
richTextBox1.Text = sb.ToString();