VB获取文件路径
有按钮1和text1.实现:单击按钮1弹出选择文件选择框(类似记事本的打开按钮)。选择文件后在text1中显示文件的绝对路径...
有按钮1和text1.实现:单击按钮1弹出选择文件选择框(类似记事本的打开按钮)。选择文件后在text1中显示文件的绝对路径
展开
5个回答
推荐于2017-11-25
展开全部
1、新建工程,并添加TextBox,CommandButton控件。
2、按Ctrl+R,在弹出的部件窗口中勾选Microsoft Common Dialog Control 6.0,单击确定,并添加一个CommonDialog控件。
3、在CommandButton中添加以下代码:
Private Sub Command1_Click()
With CommonDialog1
.DialogTitle = "请选择文件"
.Filter = "*.*|*.*"
.CancelError = False
.ShowOpen
Text1.Text = .FileName
End With
End Sub
希望这个能帮到你。
2、按Ctrl+R,在弹出的部件窗口中勾选Microsoft Common Dialog Control 6.0,单击确定,并添加一个CommonDialog控件。
3、在CommandButton中添加以下代码:
Private Sub Command1_Click()
With CommonDialog1
.DialogTitle = "请选择文件"
.Filter = "*.*|*.*"
.CancelError = False
.ShowOpen
Text1.Text = .FileName
End With
End Sub
希望这个能帮到你。
2013-07-27
展开全部
需要添加一个CommonDialog控件。
添加方法:按Ctrl+T,在弹出的对话框中选择Microsoft Common Dialog Control 6.0,单击确定,将该控件添加到工具箱中,然后将该控件画到窗体上。设置控件名称为cd。
编译器执行到cd.Action = 1,就会打开记事本中的“打开”对话框。待用户选择一个文件后,cd的FileName属性就会变为要打开的文件的路径名。
具体代码如下:
Private Sub Command1_Click()
cd.Action = 1
Text1 = cd.FileName
End Sub
望楼主采纳!!
添加方法:按Ctrl+T,在弹出的对话框中选择Microsoft Common Dialog Control 6.0,单击确定,将该控件添加到工具箱中,然后将该控件画到窗体上。设置控件名称为cd。
编译器执行到cd.Action = 1,就会打开记事本中的“打开”对话框。待用户选择一个文件后,cd的FileName属性就会变为要打开的文件的路径名。
具体代码如下:
Private Sub Command1_Click()
cd.Action = 1
Text1 = cd.FileName
End Sub
望楼主采纳!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2018-10-03
展开全部
VB2008测试通过 Imports System Imports System.IO Imports System.Threading Imports System.Windows.Forms
Public Class FrmMain
Dim newSearcher As getFileByName
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rball.Checked = True
tbpath.Text = ""
tbpath.Enabled = False
btndlg.Enabled = False
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
tv.Nodes.Clear()
btnOK.Enabled = False
btnExit.Enabled = False
If rball.Checked Then
run()
Else
If tbpath.Text = "" Then
MsgBox("请输入或者选择一个路径")
Exit Sub
Else
run(tbpath.Text)
End If
End If
End Sub
Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Click
fbdlg.RootFolder = Environment.SpecialFolder.MyComputer
fbdlg.ShowDialog()
tbpath.Text = fbdlg.SelectedPath
End Sub
Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChanged
If rbchs.Checked = True Then
tbpath.Enabled = True
btndlg.Enabled = True
Else
tbpath.Enabled = False
btndlg.Enabled = False
End If
End Sub
Private Sub run()
If tbfileName.Text = "" Then
MsgBox("请输入文件名称")
btnOK.Enabled = True
btnExit.Enabled = True
Exit Sub
Else
newSearcher = New getFileByName(tbfileName.Text)
newSearcher.GetDrivers()
tmr.Enabled = True
tmr.Interval = 10
End If
End Sub
Private Sub run(ByVal path As String)
If tbfileName.Text = "" Then
MsgBox("请输入文件名称")
btnOK.Enabled = True
btnExit.Enabled = True
Exit Sub
Else
newSearcher = New getFileByName(tbfileName.Text)
newSearcher.SearchFolder(path)
tmr.Enabled = True
tmr.Interval = 50
End If
End Sub
Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick
Lblshow.Text = newSearcher.currentPath
If newSearcher.cntThread = 0 And newSearcher.isDone Then
'MsgBox(newSearcher.getFile.ToString)
'MsgBox("全部线程结束")
For Each Str As String In newSearcher.getFile
tv.Nodes.Add(Str)
Next
'For i As Integer = 0 To newSearcher.getFile.Length - 1
'tv.Nodes.Add(newSearcher.getFile(i))
'Next
tmr.Enabled = False
btnExit.Enabled = True
btnOK.Enabled = True
End If
My.Application.DoEvents()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub End Class
Public Class FrmMain
Dim newSearcher As getFileByName
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rball.Checked = True
tbpath.Text = ""
tbpath.Enabled = False
btndlg.Enabled = False
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
tv.Nodes.Clear()
btnOK.Enabled = False
btnExit.Enabled = False
If rball.Checked Then
run()
Else
If tbpath.Text = "" Then
MsgBox("请输入或者选择一个路径")
Exit Sub
Else
run(tbpath.Text)
End If
End If
End Sub
Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Click
fbdlg.RootFolder = Environment.SpecialFolder.MyComputer
fbdlg.ShowDialog()
tbpath.Text = fbdlg.SelectedPath
End Sub
Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChanged
If rbchs.Checked = True Then
tbpath.Enabled = True
btndlg.Enabled = True
Else
tbpath.Enabled = False
btndlg.Enabled = False
End If
End Sub
Private Sub run()
If tbfileName.Text = "" Then
MsgBox("请输入文件名称")
btnOK.Enabled = True
btnExit.Enabled = True
Exit Sub
Else
newSearcher = New getFileByName(tbfileName.Text)
newSearcher.GetDrivers()
tmr.Enabled = True
tmr.Interval = 10
End If
End Sub
Private Sub run(ByVal path As String)
If tbfileName.Text = "" Then
MsgBox("请输入文件名称")
btnOK.Enabled = True
btnExit.Enabled = True
Exit Sub
Else
newSearcher = New getFileByName(tbfileName.Text)
newSearcher.SearchFolder(path)
tmr.Enabled = True
tmr.Interval = 50
End If
End Sub
Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick
Lblshow.Text = newSearcher.currentPath
If newSearcher.cntThread = 0 And newSearcher.isDone Then
'MsgBox(newSearcher.getFile.ToString)
'MsgBox("全部线程结束")
For Each Str As String In newSearcher.getFile
tv.Nodes.Add(Str)
Next
'For i As Integer = 0 To newSearcher.getFile.Length - 1
'tv.Nodes.Add(newSearcher.getFile(i))
'Next
tmr.Enabled = False
btnExit.Enabled = True
btnOK.Enabled = True
End If
My.Application.DoEvents()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub End Class
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-27
展开全部
Private Sub Command1_Click()
Dim oDLG
Set oDLG = CreateObject("MSComDlg.CommonDialog")
With oDLG
.DialogTitle = "打开文件"
.Filter = "所有文件|*.*"
.MaxFileSize = 255
.ShowOpen
If .FileName <> "" Then
Text1.text= .FileName
End If
End With
Set oDLG = Nothing
End Sub
Dim oDLG
Set oDLG = CreateObject("MSComDlg.CommonDialog")
With oDLG
.DialogTitle = "打开文件"
.Filter = "所有文件|*.*"
.MaxFileSize = 255
.ShowOpen
If .FileName <> "" Then
Text1.text= .FileName
End If
End With
Set oDLG = Nothing
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-27
展开全部
添加COMOON DIALOG控件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询