怎么用通用对话框打开文件?

null_name 2006-04-19 10:46:00
private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
//我想通过openFileDialog在rtfTex中显示打开的文件,参 数怎么弄?
this.rtfText.LoadFile();


}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("No file to load yet");
}
}
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
BinaryTreeEx 2006-04-20
  • 打赏
  • 举报
回复
OpenFileDialog cOpenFileDialog = new OpenFileDialog();
cOpenFileDialog.Filter = "wav files (*.wav)|*.wav|mp3 files (*.mp3)|*.mp3";
cOpenFileDialog.FilterIndex = 1;

if (cOpenFileDialog.ShowDialog() == DialogResult.OK)
{
if (cOpenFileDialog.FileName == null || cOpenFileDialog.FileName == "")
{
MessageBox.Show("Please select a file.");
return;
}
if (File.Exists(cOpenFileDialog.FileName) == false)
{
MessageBox.Show("The picture file is not exist.");
return;
}
if (LoadVoiceFile(cOpenFileDialog.FileName) != SYS_RETURN.OK)
MessageBox.Show("Fail to open picture file.");
}
Knight94 2006-04-20
  • 打赏
  • 举报
回复
private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
this.rtfText.LoadFile(openFileDialog.FileName);//Use file name from open-dialog


}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("No file to load yet");
}
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧