private void button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "*.txt|*.txt";//设置文件 DialogResult dr = openFileDialog1.ShowDialog();//显示打开文件对话框 if (dr ==DialogResult.OK) { richTextBox1.Text = System.IO.File.ReadAllText(openFileDialog1.FileName, Encoding.Default); } }运行结果如图所示:
时间: 2024-12-15 05:50:02