如何在运行应用程序时不断更新列表。 VB

时间:2013-05-24 11:53:59

标签: vb.net winforms

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

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

2 个答案:

答案 0 :(得分:1)

我认为你正在寻找FileSystemWatcher Class

  

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

答案 1 :(得分: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