1

如何让我的列表在我的应用程序运行时一直更新,而不是仅在我启动我的应用程序时更新?

Private Sub Form1_Load(ByVal sender As System.Object,
                          ByVal e As System.EventArgs) Handles MyBase.Load
    On Error Resume Next
    Dim username As String
    username = SystemInformation.UserName
    Dim filesInFolder As String
    filesInFolder= "C:\Users\" + username + "\AppData\Roaming\pictures\pics"

    Dim di As New IO.DirectoryInfo(filesInFolder)
    Dim aryFi As IO.FileInfo() = di.GetFiles("*.jpg")
    Dim fi As IO.FileInfo

        For Each fi In aryFi
            list.Items.Add(fi.Name)
        Next
End Sub
4

2 回答 2

1

我认为您正在寻找FileSystemWatcher Class

侦听文件系统更改通知并在目录或目录中的文件更改时引发事件。

于 2013-05-24T18:24:04.727 回答
0

你可以使用定时器。

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim timer as New windows.forms.timer
    AddHandler timer.Tick, Addressof MyTimerHandlersSub        
    timer.start()

    End Sub

    Private Sub MyTimerHandlersSub(ByVal sender As System.Object, ByVal e As
System.EventArgs)
       'Update Your List Here.
    End Sub 
于 2013-05-24T12:53:34.257 回答