[简单明了提问]求一个线程中修改另一个控件属性的代码
首先,输入:
-------------------
Private a(100) as String
For i=0 to 100
a(i)=CStr(i)
Next
然后,写一个线程中需要将a(i)写入ListBox。
线程需要达到的功能大致就是:
----------------------------
While i=0
ListBox1.Items.Add(a(i))
End While
最后,麻烦各位大大解答这一简单无比的问题。
[解决办法]
如果不是vs2010或是不支持Lambda和匿名方法,则这样写
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As New Threading.Thread(AddressOf ThreadProc) t.IsBackground = True t.Start() End Sub Public Sub ThreadProc() For i As Integer = 0 To 100 Me.ListBox1.Invoke(New UpdateListBoxHandler(AddressOf UpdateListBox), New Object() {i}) Next i End Sub Public Delegate Sub UpdateListBoxHandler(ByVal value As Integer) Public Sub UpdateListBox(ByVal value As Integer) Me.ListBox1.Items.Add(value.ToString()) Me.ListBox1.Update() Threading.Thread.Sleep(10) End Sub