Reputation: 15
Uh, yeah. This one's pretty straight forward. I made a label in the form design section (Label1), and Label1.text isn't working.
Public Class Countdown
Private WithEvents CountDwnTimer As New Timer() With {.Interval = 1000}
Public CountdownValue = 6
Private Sub Countdown_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.FormBorderStyle = FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
AddHandler CountDwnTimer.Tick, AddressOf CountDwnTimer_Tick
CountDwnTimer.Start()
End Sub
Private Sub CountDwnTimer_Tick(sender As Object, e As EventArgs)
If CountdownValue > 0 Then
CountdownValue -= 1
Label1.Text = CountdownValue.ToString
ElseIf CountdownValue = 0 Then
CountDwnTimer.Stop()
Me.BackColor = Color.White
Me.Opacity = 100
Label1.ForeColor = Color.Black
Label1.BackColor = Color.White
Label1.Text = "Capturing, don't move your mouse!"
Threading.Thread.Sleep(2000)
Me.Hide()
Else
MessageBox.Show("Error! Application flow interrupted.")
End If
End Sub
End Class
This is my code. Note that the countdown works fine (this code changes the label to show a countdown), but when I try to do Label1.Text = "Capturing, don't move your mouse!"
it doesn't work! Also, Label1.BackColor = Color.White
does not work. It also seems to be just with the Label code, because the code after it works.
Am I just seeing right past an obvious issue?
Thanks.
Upvotes: 0
Views: 55
Reputation: 54467
As it is, the changes you make to those properties can't actually show up until that method completes, but you immediately sleep the UI thread and then hide the form. You would need to call Refresh
on the Label
after setting its properties to force the changes to show up before executing the subsequent code.
Upvotes: 1