如何将“浏览到文件"对话框添加到VB.NET应用程序 [英] How to add a Browse To File dialog to a VB.NET application

查看:68
本文介绍了如何将“浏览到文件"对话框添加到VB.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB.NET Windows窗体应用程序中,如何为某人单击按钮或图像并打开文件浏览器以浏览该文件并将其路径分配给变量的功能添加功能,以便可以将该文件复制到另一个文件中具体路径?

In a VB.NET Windows Forms application how do I add the capability for someone to click a button or image and open a file browser to browse to a file and assign it's path to a variable so I can copy that file to another specific path?

推荐答案

您应该像这样使用OpenFileDialog类

You should use the OpenFileDialog class like this

Dim fd As OpenFileDialog = New OpenFileDialog() 
Dim strFileName As String

fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\"
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True

If fd.ShowDialog() = DialogResult.OK Then
   strFileName = fd.FileName
End If

然后您可以使用File类.

Then you can use the File class.

这篇关于如何将“浏览到文件"对话框添加到VB.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆