I was playing around with a list(of T) of labels to see how they were created/stored etc. I decided I would change the background colour based on the value of the NumericUpDown. The app does not throw an error but it does not change the background colour either. I tried with .Enabled and that worked fine. I also tried setting the backcolour of another label directly but that also has no effect. I have searched the net and all I can find is that
should work.
Here is my code, where am I going wrong?
vb.net Code:
Label1.BackColor = Color.Azure
Here is my code, where am I going wrong?
vb.net Code:
Imports System.Collections Imports System.Drawing Public Class Form Dim iLast As Integer = -1 Dim Lbls As New List(Of Label) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Clear() Lbls.Clear() For Each ctrl As Control In Me.Controls If ctrl.Name.Contains("Label") Then Lbls.Add(CType(ctrl, Label)) End If Next ListBox1.Items.Add("direct from load") For ptr As Integer = 0 To Lbls.Count - 1 ListBox1.Items.Add(Lbls(ptr).Name) Next Lbls.Sort(Function(x, y) (x.Name.CompareTo(y.Name))) ListBox1.Items.Add("after sort") For ptr As Integer = 0 To Lbls.Count - 1 ListBox1.Items.Add(Lbls(ptr).Name) Next For ptr As Integer = 0 To Lbls.Count - 1 Lbls(ptr).Text = ptr.ToString Next lblInfo.BackColor = Color.Azure End Sub Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChanged If iLast <> -1 Then Lbls(iLast).BackColor = Color.FromKnownColor(KnownColor.Control) Lbls(CInt(NumericUpDown1.Value)).BackColor = Color.Azure End If iLast = CInt(NumericUpDown1.Value) End Sub End Class