sperodev
asked on
why "CType(sender,....", instead of the object, itself?
I am studying for the MCAD 70-306 exam, using Gunderloy. I notice that he often has code such as the following:
Private Sub dudColor_SelectedItemChang ed( ByVal sender As System.Object, ByVal e As ystem.EventArgs) _
Handles dudColor.SelectedItemChang ed
' Typecast the object to DomainUpDown
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown)
' Change color of lblsampleText to selected color
lblSampleText.ForeColor = Color.FromName(dudCol.Text )
End Sub
My question is, since you have access to dudColor, why bother with
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown) ???
Why can't you, or shouldn't you, just write:
lblSampleText.ForeColor = Color.FromName(dudColor.Te xt) ???
Private Sub dudColor_SelectedItemChang
Handles dudColor.SelectedItemChang
' Typecast the object to DomainUpDown
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown)
' Change color of lblsampleText to selected color
lblSampleText.ForeColor = Color.FromName(dudCol.Text
End Sub
My question is, since you have access to dudColor, why bother with
Dim dudCol As DomainUpDown = CType(sender, DomainUpDown) ???
Why can't you, or shouldn't you, just write:
lblSampleText.ForeColor = Color.FromName(dudColor.Te
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks also to sognoct.
This function can handle more than one kind of sender, so the nature of the sender can be different and also its methods