【发布时间】:2020-08-27 00:54:56
【问题描述】:
我有一个表单可以检查文件夹中是否有一些更改。我使用 FileSystemWatcher 执行此操作。 当通知更改时,必须加载另一个表单。第二个窗体已加载,但控件不可见。当我通过单击按钮加载第二个表单时,控件是可见的。我认为这是因为 If 语句,但我不确定。有人可以帮我解决这个问题吗?
Imports System.IO
'Imports System.Diagnostics
Public Class Settings
Public watchfolder As FileSystemWatcher
Private Sub Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txt_watchpath.Text = "D:\temp"
If txt_watchpath.Text = "" Then
btn_startwatch.Enabled = False
End If
End Sub
Private Sub txt_watchpath_TextChanged(sender As Object, e As EventArgs) Handles txt_watchpath.TextChanged
If Me.Text <> "" Then
btn_startwatch.Enabled = True
End If
End Sub
Private Sub btn_startwatch_Click(sender As Object, e As EventArgs) Handles btn_startwatch.Click
watchfolder = New System.IO.FileSystemWatcher()
'this is the path we want to monitor
watchfolder.Path = txt_watchpath.Text
'Add a list of Filter we want to specify
'make sure you use OR for each Filter as we need to
'all of those
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or
IO.NotifyFilters.LastWrite
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or
IO.NotifyFilters.Attributes
' add the handler to each event
AddHandler watchfolder.Changed, AddressOf logchange
AddHandler watchfolder.Created, AddressOf logchange
'AddHandler watchfolder.Deleted, AddressOf logchange
' add the rename handler as the signature is different
AddHandler watchfolder.Renamed, AddressOf logrename
'Set this property to true to start watching
watchfolder.EnableRaisingEvents = True
watchfolder.IncludeSubdirectories = False
btn_startwatch.Enabled = False
btn_stop.Enabled = True
Me.Hide()
'End of code for btn_start_click
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
FrmPopup.Fullpath = e.FullPath
FrmPopup.Activity = e.Name & " is changed"
FrmPopup.Show()
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
FrmPopup.Fullpath = e.FullPath
FrmPopup.Activity = e.Name & " is made"
test.Show()
End If
End Sub
Private Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
FrmPopup.Fullpath = e.FullPath
FrmPopup.Activity = e.OldName & " is changed to " & e.Name
FrmPopup.Show()
End Sub
Private Sub btn_stop_Click(sender As Object, e As EventArgs) Handles btn_stop.Click
FrmPopup.Show()
End Sub
End Class
【问题讨论】:
-
向我们展示您用于通过单击加载表单的代码与此代码。我在发布的代码中没有看到 `=New FrmPopup()`。
-
@LarsTech,我将完整的代码放入问题中。在`Private Sub btn_stop_Click(sender As Object, e As EventArgs) Handles btn_stop.Click`中是按钮点击语句来显示弹出表单。弹出表单只是一个带有两个标签和一个按钮的表单。当我点击按钮时。控件在弹出表单中可见。
-
test.Show()在做什么? -
同FrmPopup.Show()。它是另一种带有按钮的表单。只是看看 FrmPopup 是否有问题。