C#按键打开文件选择对话框,并把选择好的路径保存/显示到textBox

 

1.选择文件夹

FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = "D:";//默认路径
if(fbd .ShowDialog() == DialogResult.OK)
  {
    textBox_hex_file_path.Text = fbd.SelectedPath;

  }
}

 

2.选择文件路径

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "e:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
textBox_hexfile_path.Text = openFileDialog.FileName;
}

 

 

3.文件类型限制

文本文件|*.*| C#文件|*.cs| 所有文件|*.*";

文本文件|*.*

C#文件|*.cs

 所有文件|*.*

posted @ 2014-12-09 20:21  fx427103  阅读(893)  评论(0编辑  收藏  举报