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