Hi,
After dealing with the pain-in-the-____ error "The path is not on a legal form" witch only occured after dragging a file system watcher onto the form, by creating the file watcher in the code. When an event is raised, i have to tell the user what happened. I can do this using messageboxes, without any problem. But, when I wanted the output to be displayed in a textbox, the program terminates without any warning.
Here is what my code looks like:
Public Class Form1
Public watchfolder As FileSystemWatcher
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = "c:\temp"
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
IO.NotifyFilters.Attributes
watchfolder.Filter = "*.*"
AddHandler watchfolder.Changed, AddressOf logchange
AddHandler watchfolder.Created, AddressOf logchange
AddHandler watchfolder.Deleted, AddressOf logchange
AddHandler watchfolder.Renamed, AddressOf logrename
watchfolder.EnableRaisingEvents = True
TextBox1.Text = "Changelogging started."
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As _
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
MsgBox("Item Updated: " & e.FullPath)
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
TextBox1.Text &= "Item Created"
End If
If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
MsgBox("Item Deleted: " & e.FullPath)
End If
'code above works perfectly well, unlike the code below
End Sub
Public Sub logrename(ByVal source As Object, ByVal e As _
System.IO.RenamedEventArgs)
TextBox1.Text &= "File" & e.OldName & _
" has been renamed to " & e.Name & vbCrLf
e.Name)
End Sub
End Class
I have no clue on how to fix this, also because i don't get an error or any output from VS
Thanks in advance, Brecht