【发布时间】:2013-03-07 15:22:52
【问题描述】:
我目前正在打开一个文件并将其显示在消息框上。
private void button2_Click_1(object sender, EventArgs e)
{
//OpenFileDialog1.ShowDialog();
OpenFileDialog file = new OpenFileDialog();
file.FileName = "";
file.Title = "Open A Text document.";
file.Filter = "(*.gc)|*.gc|(*.etf)|*.etf|(*.txt)|*.txt|(*.GC)|*.GC|(*.tap)|*.tap";
DialogResult result = file.ShowDialog();
if (result == DialogResult.OK)
{
System.IO.StreamReader OpenFile = new System.IO.StreamReader(file.FileName);
textBox1.Text = OpenFile.ReadToEnd();
OpenFile.Close();
}
if (file.FileName.Length > 0)
{
OpenFile(file.FileName);
}
但我需要逐行读取文件并将其显示在消息框上。有没有办法更改此代码。
【问题讨论】:
-
您是说要为文件中的每一行显示一个单独的消息框吗?
-
使用 ReadLine() 代替 ReadToEnd
-
我想在同一个消息框中显示
-
@Sthn 那么您想在一个消息框中显示整个文件吗?你试过
MessageBox.Show(OpenFile.ReadToEnd());吗? -
@Sthn 为什么需要逐行阅读