Hi all, I have a problem with understanding how to use the TryCast operator. I've tried all different object and dataType variations and guess I just don't get it. I am supposed to use the TryCast operator to determine if the object passed into this procedure is the textbox or the label. Change the ForeColor property of the object to be the color assigned to the newColor variable. I'm to do this in the ChangeColor Sub procedure. Here's my code so far:
Any hints would be appreciated. Thanks.
CODE
Option Strict On
Option Explicit On
Option Infer On
Public Class mainForm
Private newColor As Color
Private Sub ChangeColor(ByVal sender As Object)
End Sub
Private Sub startButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles startButton.Click
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
clockLabel.Text = DateTime.Now.ToLongTimeString
End Sub
Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim changeObject As Object
'decide which control to change
If DateTime.Now.Second Mod 5 = 0 Then
changeObject = nameTextBox
Else
changeObject = clockLabel
End If
'set the new color
If DateTime.Now.Second Mod 2 = 0 Then
newColor = Color.Coral
Else
newColor = Color.BlueViolet
End If
ChangeColor(changeObject)
End Sub
End Class