OpenFileDialog openText = new OpenFileDialog();
openText.DefaultExt = "txt";
if (openText.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openText.FileName,RichTextBoxStreamType.RichText);
}运行报错 说文件格式不正确!
openText.DefaultExt = "txt";
if (openText.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openText.FileName,RichTextBoxStreamType.RichText);
}运行报错 说文件格式不正确!
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog(); // Initialize the OpenFileDialog to look for RTF files.
openFile1.DefaultExt = "*.rtf";
openFile1.Filter = "RTF Files|*.rtf"; // Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName);
}
}