我有这个自定义类
Public Class labelScroll
Inherits Label
Public Shadows Property Text As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
Dim add As String = ""
Dim result As String()
Dim i As Integer
result = Split(value, vbLf)
Dim n As Integer = 30
If (result.Length < n) Then
n = result.Length
End If
Dim start As Integer = result.Length - n
For i = start To result.Length - 1 Step 1
add += result(i) + Environment.NewLine
Next
MyBase.Text = add
End Set
End Property
End Class
我有一个表单,我放置了这个 labelScroll 并且还放置了一个按钮:我有这个按钮的点击事件的代码:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
LabelScroll1.Text = "1"
Threading.Thread.Sleep(1000)
LabelScroll1.Text += "2"
Threading.Thread.Sleep(1000)
LabelScroll1.Text += "3"
End Sub
当我点击按钮时会发生什么,它需要 2 秒,然后在三行上只显示“1”“2”“3”。实际应该发生的是,当用户单击按钮时,“1”出现然后Threading.Thread.Sleep(1000)
被执行,因此程序等待 1 秒然后在下一行打印“2”。
为什么没有发生这种情况?