夏樾 2019-08-20 10:38 采纳率: 0%
浏览 451

请问大家c#窗体设计菜单打开文件功能时打不开想要打开的文件是为什么?

请问大家c#窗体设计菜单打开文件功能时打不开想要打开的文件是为什么

代码
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//获取文件位置
richTextBox.LoadFile(fileName + @"\tt.txt");
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//获取文件位置
richTextBox.SaveFile(fileName + "\tt.txt");
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-08-20 10:43
    关注

    这样写

    OpenFileDialog ofn = new OpenFileDialog();
    if (ofn.ShowDialog() == DialogResult.OK)
    richTextBox.LoadFile(ofn.FileName);

    评论

报告相同问题?