我尝试打开一个textdocument然后收到消息:来自try-catch
的文件格式无效。我使用Visual Studio 2015与Visual C#和Windows窗体应用程序。
这是我的open函数代码:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
try {
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog();
// Initialize the OpenFileDialog to look for RTF files.
openFile1.Filter = "Text Files (*.txt)|*.txt| RTF Files (*.rtf)|*.rtf| All (*.*)|*.*";
// 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.
TextBox.LoadFile(openFile1.FileName);
}
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
}//end open
我希望你能帮助我赐予友好的祝福。