Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

VS 2010 [RESOLVED] label1.backcolor = color.azure does not give error nor change the background colour

$
0
0
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
vb.net Code:
  1. Label1.BackColor = Color.Azure
should work.

Here is my code, where am I going wrong?
vb.net Code:
  1. Imports System.Collections
  2. Imports System.Drawing
  3.  
  4. Public Class Form
  5.     Dim iLast As Integer = -1
  6.     Dim Lbls As New List(Of Label)
  7.  
  8.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  9.  
  10.         ListBox1.Items.Clear()
  11.         Lbls.Clear()
  12.         For Each ctrl As Control In Me.Controls
  13.             If ctrl.Name.Contains("Label") Then
  14.                 Lbls.Add(CType(ctrl, Label))
  15.             End If
  16.         Next
  17.         ListBox1.Items.Add("direct from load")
  18.         For ptr As Integer = 0 To Lbls.Count - 1
  19.             ListBox1.Items.Add(Lbls(ptr).Name)
  20.         Next
  21.         Lbls.Sort(Function(x, y) (x.Name.CompareTo(y.Name)))
  22.         ListBox1.Items.Add("after sort")
  23.         For ptr As Integer = 0 To Lbls.Count - 1
  24.             ListBox1.Items.Add(Lbls(ptr).Name)
  25.         Next
  26.         For ptr As Integer = 0 To Lbls.Count - 1
  27.             Lbls(ptr).Text = ptr.ToString
  28.         Next
  29.         lblInfo.BackColor = Color.Azure
  30.     End Sub
  31.  
  32.     Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChanged
  33.         If iLast <> -1 Then
  34.             Lbls(iLast).BackColor = Color.FromKnownColor(KnownColor.Control)
  35.             Lbls(CInt(NumericUpDown1.Value)).BackColor = Color.Azure
  36.         End If
  37.         iLast = CInt(NumericUpDown1.Value)
  38.     End Sub
  39. End Class

Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>