0

我有以下代码,它只是打开一个包含 txt 文件的文件夹。

Private Sub OpenTabpageTextFolderToolStripMenuItem_Click( _
            ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles OpenTabpageTextFolderToolStripMenuItem.Click
  Dim OpenFolder = (RootDrive & "QuickEmailer2\TabTxt")
  Process.Start("explorer.exe", OpenFolder)
End Sub

然后用户编辑一个 txt 文件,然后关闭。我想调用我的刷新代码并利用对 txt 文件的更改,但是如果我在 process.start 之后调用,它无需等待即可运行?

我可以使用代码进行这些编辑,但是有 80 个文件可供选择,并且在第一次设置程序时只需要编辑一次(或两次)。

我确信有一段代码说:

Private Sub OpenTabpageTextFolderToolStripMenuItem_Click( _
            ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles OpenTabpageTextFolderToolStripMenuItem.Click
  Dim OpenFolder = (RootDrive & "QuickEmailer2\TabTxt")
  Process.Start("explorer.exe", OpenFolder)
  '**I will hang on here while you do your stuff, then I will continue...**
  Call RefreshfromAllTxtFiles()
End Sub
4

2 回答 2

2

替代解决方案:首次使用 2 个按钮/步骤设置程序!

  1. 按钮/步骤#1:打开设置文件
  2. 按钮/步骤 #2:设置文件已修改...继续!
于 2013-05-23T15:19:58.677 回答
1

根据 Steve 的评论,您可以使用 FileSystemWatcher 来监视对目录的更改。这样的事情可以让你开始:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim fsw As FileSystemWatcher
    fsw = New System.IO.FileSystemWatcher()

    'this is the folder we want to monitor
    fsw.Path = "c:\temp"
    fsw.NotifyFilter = IO.NotifyFilters.Attributes

    AddHandler fsw.Changed, AddressOf IveBeenChanged
    fsw.EnableRaisingEvents = True
End Sub
Private Sub IveBeenChanged(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
    If e.ChangeType = IO.WatcherChangeTypes.Changed Then
        'this displays the file that changed after it is saved
        MessageBox.Show("File " & e.FullPath & " has been modified")

        ' you can call RefreshfromAllTxtFiles() here
    End If
End Sub
于 2013-05-23T15:39:01.760 回答