-3
我的winform上有一個標籤,當表單加載時,計算一個目錄中有多少個文件。我想在winform應用程序運行時每隔n秒更新一次該標籤。我不知道如何達致這,這裏的一對負載我來算的文件:如何在winform上每隔n秒更新一次標籤控件?
Public Function getUserCountsTotal() As Integer
Dim di As New DirectoryInfo("C:\myDirectory")
Dim Users As FileInfo() = di.GetFiles().OrderByDescending(Function(fi) fi.LastWriteTime).ToArray()
Dim user As FileInfo
'list the names of all files in the specified directory
For Each user In Users
ComboBox1.Items.Add(Path.GetFileNameWithoutExtension(user.Name) & "- " & user.LastWriteTime)
Next
getUserCountsTotal = ComboBox1.Items.Count + 1
End Function
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
statusPanel.Text = ""
statusPanel.Text = "Logged in as " & getYourUserName() & " - " & "[ " & getUserCountsTotal() & " ] "
End Sub
使用[定時器?](https://msdn.microsoft.com/zh-cn/library/system。 windows.forms.timer(v = vs.110).aspx) –
這個數字總是加起來,因爲你不停地向'ComboBox'添加新的項目而不刪除舊的項目。你需要調用[**'ComboBox.Items.Clear()'**](https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.objectcollection.clear(v = vs.110).aspx),然後再開始添加新項目。 –