private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string txt = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text File|*.txt";
ofd.FileName = "File";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
while (txt != null) {
txt += sr.ReadLine() + "\n";
if (txt != null) richTextBox1.Text += txt;
else sr.Dispose();
}
}
}
这是我的代码,旨在在单击“菜单条”项打开时运行。但不知何故,这会卡在我的应用程序上。代码中的错误是什么?