private void button_Click(object sender, EventArgs e) { string fileName =string.Empty; //文件名 //打开文件 OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = "txt"; dlg.Filter = "Txt Files|*.txt"; if (dlg.ShowDialog() == DialogResult.OK) fileName = dlg.FileName; if (fileName == null) return; //读取文件内容 StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default); String ls_input = sr.ReadToEnd().TrimStart(); if (!string.IsNullOrEmpty(ls_input)) isopen = true; sr.Close(); }