我有一个包含2个表单的项目。 Form1和form2。
对于Form1,代码为:
Public Class Form1
Dim thread As System.Threading.Thread
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Show()
End Sub
Private Sub countup(ByVal startFrom As Integer)
For startFrom = startFrom To startFrom + 10000
startFrom += 1
Form2.Label1.Text = startFrom
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
thread = New System.Threading.Thread(AddressOf countup)
thread.Start(1000)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
thread.Abort()
End Sub
End Class
在Form2中,我只有一个名为label1的标签。 我需要从Form1中启动的线程刷新Form2上的label1.text。 该程序运行没有错误,但没有任何反应。 form2上的Label1.text不会修改。 这该怎么做? 提前致谢
答案 0 :(得分:0)
解决方案:
Invoke(Sub()
Form2.Label1.Text = startFrom
End Sub)