|
-
May 20th, 2009, 09:48 PM
#1
Thread Starter
Stack Overflow moderator
Search Application won't search?
My search application isn't working. When the "Search" window pops up, the label stays frozen on "C:\". The application isn't freezing, just the search. Why? I can still use the buttons on it, and everything else seems to work fine.
Please help!
Last edited by minitech; May 20th, 2009 at 09:58 PM.
-
May 20th, 2009, 09:52 PM
#2
Re: Search Application won't search?
Like many people, I am not a big fan of downloading entire projects unnecessarily. I'm fairly sure that you could just post the code for the method in question directly, at least as a first attempt.
Also, I'm not sure that you have but just make sure you haven't included any binary files in that attachment as it's against forum rules. Always delete the bin and obj folders before zipping projects.
-
May 20th, 2009, 09:57 PM
#3
Thread Starter
Stack Overflow moderator
Re: Search Application won't search?
Fine. By the way, I haven't included the CMessageBox class. It's just a messagebox with fancy graphics.
Form1 (main form):
vb.net Code:
Public Class Form1
Private Sub txtSearch_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearch.GotFocus
If Me.txtSearch.Text = "Type your search here" Then
Me.txtSearch.ForeColor = Color.White
Me.txtSearch.Text = ""
End If
End Sub
Private Sub txtSearch_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearch.LostFocus
If Me.txtSearch.Text = "" Then
Me.txtSearch.ForeColor = Color.Gray
Me.txtSearch.Text = "Type your search here"
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.X And e.Alt Then Me.Close()
End Sub
Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseLeave
Dim cpos As New Point(Me.Location.X + Windows.Forms.Cursor.Position.X, Me.Location.Y + Windows.Forms.Cursor.Position.Y)
Dim rect As New Rectangle(Me.Location, Me.Size)
If Not rect.Contains(cpos) Then Me.Opacity = 0.75
End Sub
Private Sub Any_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Opacity = 1.0#
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 0
AddHandler Me.MouseHover, AddressOf Any_MouseHover
While i < Me.Controls.Count
AddHandler Me.Controls(i).MouseHover, AddressOf Any_MouseHover
i += 1
End While
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
If Me.txtSearch.Text = "" Or Me.txtSearch.ForeColor = Color.Gray Then
Dim f As New CMessageBox("You must enter search terms!", "Search", SystemIcons.Exclamation)
f.ShowDialog()
Else
Dim f As New Searcher(Me.txtSearch.Text)
Me.Hide()
f.Owner = Me
f.Show()
f.Search()
Me.Show()
'AddHandler f.FormClosed, AddressOf ShowSelf
End If
End Sub
Private Sub ShowSelf(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Me.Show()
End Sub
End Class
and Searcher (the searching form):
vb.net Code:
Public Class Searcher
Dim _searchdir As String = "C:\"
Dim _searchterm As String = ""
Structure ResultInfo
Dim FileName As String
Dim ParentDirectory As String
End Structure
Dim t As System.Threading.Thread
Delegate Sub NoArgsD()
Delegate Sub AddResultDef(ByVal arg As ResultInfo)
Delegate Sub SetTextDef(ByVal text As String)
Dim doaddresult As AddResultDef = New AddResultDef(AddressOf AddResult)
Dim dosetsttext As SetTextDef = New SetTextDef(AddressOf SetStatusText)
Dim dofinished As NoArgsD = New NoArgsD(AddressOf Finished)
Public Sub New(ByVal searchdir As String)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_searchdir = searchdir
End Sub
Private Sub Finished()
Me.lblCurrentSearch.Text = "Done."
Me.btnStopSearch.Visible = False
Dim f As New CMessageBox("Search complete.", "Search", SystemIcons.Information)
t = Nothing
End Sub
Public Sub Search()
t = New Threading.Thread(AddressOf InitSearch)
t.Start()
End Sub
Private Sub InitSearch()
On Error GoTo sub_exit
DoSearch(_searchdir)
Me.Invoke(dofinished)
sub_exit:
End Sub
Private Sub DoSearch(ByVal dir As String)
Dim di, cdi As System.IO.DirectoryInfo
Dim fi As System.IO.FileInfo
cdi = New IO.DirectoryInfo(dir)
If cdi.Name.Contains(_searchterm) Then
Dim rs As ResultInfo
rs.FileName = cdi.Name
If Not cdi.Parent Is Nothing Then
rs.ParentDirectory = cdi.Parent.FullName
Else
rs.ParentDirectory = "My Computer"
End If
End If
For Each fi In cdi.GetFiles()
If fi.Name.Contains(_searchterm) Then
Dim ri As ResultInfo
ri.FileName = fi.Name
ri.ParentDirectory = cdi.FullName
Me.Invoke(doaddresult, ri)
End If
Next
For Each di In cdi.GetDirectories()
Me.Invoke(dosetsttext, "Currently Searching " & di.FullName)
DoSearch(di.FullName)
Next
End Sub
Private Sub AddResult(ByVal result As ResultInfo)
Dim lvi As New ListViewItem(New String() {result.FileName, result.ParentDirectory})
Me.lstSearchResults.Items.Add(lvi)
lvi = Nothing
End Sub
Private Sub SetStatusText(ByVal str As String)
Me.lblCurrentSearch.Text = str
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
If Not t Is Nothing Then
t.Abort()
End If
Me.Close()
End Sub
Private Sub btnStopSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopSearch.Click
t.Abort()
Me.btnStopSearch.Visible = False
Me.lblCurrentSearch.Text = "Search stopped."
End Sub
End Class
-
May 20th, 2009, 10:03 PM
#4
Thread Starter
Stack Overflow moderator
Re: Search Application won't search?
Or could it just be slow? Google Desktop is indexing my files right now...
Still, I waited a while for the "current directory" label to change, but nothing happened...
-
May 21st, 2009, 06:43 PM
#5
Thread Starter
Stack Overflow moderator
Re: Search Application won't search?
Ok, not google desktop. I turned it off and waited a really long time, the label doesn't even change...
What's going wrong? Also, the form behind it seems frozen. It won't hide. Also, if this is important, ShowInTaskbar is set to False on #1 and True on #2.
I have no idea what's happening! Please help!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|