操作环境:Visual Studio 2015
打开文件:
- private void openFile_C++lick(object sender, EventArgs e)
- {
- // 定义一个打开文件控件
- OpenFileDialog fileDlg = new OpenFileDialog();
- // 设置打开控件后,默认陌路为exe运行目录
- fileDlg.InitialDirectory = Application.StartupPath;
- // 设置控件打开的文件类型
- fileDlg.Filter = “hex files (*.hex)|*.hex”;
- // 设置控件打开文件类型的显示顺序
- fileDlg.FilterIndex = 1;
- // 设置对话框是否记忆之前打开的目录
- fileDlg.RestoreDirectory = true;
- if(fileDlg.ShowDialog()==DialogResult.OK)
- {
- textBox_fileAddress.Text = fileDlg.FileName;
- }
- }
打开文件夹:
- private void button1_C++lick(object sender, EventArgs e)
- {
- //打开文件夹浏览
- FolderBrowserDialog folderBrowserDiglog = new FolderBrowserDialog();
- folderBrowserDiglog.ShowDialog();
- //显示选择的路径
- textBox1.Text = folderBrowserDiglog.SelectedPath;
- }