C#代码如下:
// 获取文件夹绝对路径 显示在 txtbox 控件里
System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
if (folder.ShowDialog() == DialogResult.OK)
{
this.txtboxPath.Text = folder.SelectedPath;
}
// 获取文件和路径名 一起显示在 txtbox 控件里
OpenFileDialog dialog = new OpenFileDialog();
if (dialog .ShowDialog() == DialogResult.OK)
{
this.txtboxPath.SelectedText = dialog.FileName;
}
//如果只显示文件名
OpenFileDialog dialog = new OpenFileDialog();
if (dialog .ShowDialog() == DialogResult.OK)
{
this.txtboxPath.SelectedText = dialog.SafeFileName;
}
VB.NET代码如下:
' 获取文件夹绝对路径 显示在 txtbox 控件里
Dim folder As New System.Windows.Forms.FolderBrowserDialog()
If folder.ShowDialog() = DialogResult.OK Then
Me.txtboxPath.Text = folder.SelectedPath
End If
' 获取文件和路径名 一起显示在 txtbox 控件里
Dim dialog As New OpenFileDialog()
If dialog.ShowDialog() = DialogResult.OK Then
Me.txtboxPath.SelectedText = dialog.FileName
End If
'如果只显示文件名
Dim dialog As New OpenFileDialog()
If dialog.ShowDialog() = DialogResult.OK Then
Me.txtboxPath.SelectedText = dialog.SafeFileName
End If