为这个控件添加一个textBox1_KeyDown事件
在这个事件中实现打开一个对话框
可以选择任何文件
点确定后
将这个文件的路径在textBox1的textBox1.text中显示出来
3 个解决方案
#1
OpenFileDialog openFileDialog1=new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
FileInfo info = new FileInfo(fileName);
}
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
FileInfo info = new FileInfo(fileName);
}
#2
用folderBrowserDialog控件
folderBrowserDialog1.Description = "请选择工程源码路径。";
if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
{
this.textBox1.Text = folderBrowserDialog1.SelectedPath;
}
folderBrowserDialog1.Description = "请选择工程源码路径。";
if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
{
this.textBox1.Text = folderBrowserDialog1.SelectedPath;
}
#3
额.. 错了 文件的话是OpenFileDialog
#1
OpenFileDialog openFileDialog1=new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
FileInfo info = new FileInfo(fileName);
}
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog1.FileName;
FileInfo info = new FileInfo(fileName);
}
#2
用folderBrowserDialog控件
folderBrowserDialog1.Description = "请选择工程源码路径。";
if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
{
this.textBox1.Text = folderBrowserDialog1.SelectedPath;
}
folderBrowserDialog1.Description = "请选择工程源码路径。";
if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
{
this.textBox1.Text = folderBrowserDialog1.SelectedPath;
}
#3
额.. 错了 文件的话是OpenFileDialog