【发布时间】:2015-03-13 00:43:02
【问题描述】:
Imports System.Threading.Thread
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
While i <= 10
TextBox1.Text = i.ToString()
TextBox1.Refresh()
Sleep(1000)
i = i + 1
End While
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim lbl As Label
Dim matches() As Control
matches = Me.Controls.Find("Label" & TextBox1.Text, True)
If matches.Length > 0 AndAlso TypeOf matches(0) Is Label Then
lbl = DirectCast(matches(0), Label)
lbl.BackColor = Color.Yellow
End If
End Sub
End Class
如果我单击 button1,那么它会在一秒钟后在文本框中显示 1 到 10。它工作正常。当 textbox.text=2 时单击 button1 后,我想按下 button2。如果我按下按钮 2,那么它应该显示 label2.backcolor=yellow。标签号是 textbox.text。问题是:在button1中完成while循环后,只有我可以按下button2。完成 while 循环后,我们只得到黄色的 label10。解决方案:我想在结束while循环之前点击那个button2。请给出解决方案。其实我想在 textbox1.text 中显示哪个数字,该标签应该是黄色的。
【问题讨论】:
-
您需要为 Button1.Click 处理程序启动一个新线程。您可以通过搜索 Google 了解如何做到这一点。
标签: vb.net