Ya3goobs Ya3goobs -5 years ago 258
Vb.net Question

How to change label color in vb.net using codes?

I want to know how to change the color of a label using its code, something like:

dim r as color
r = color.red

How do I use or assign that code to a label from a button...? Like in my form button and a label.. when the button is clicked the label changes its color .. how do I do that in vb.net?.

Here is my button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim r As Color
r = Color.Red

End Sub

End Class


Answer Source

You have defined a variable which is not the right way to do it. A label exposes some properties and to achieve your goal you simply do this:

 Label1.BackColor = Color.Aqua
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download