我正在尝试使用循环更改存储在数组中的标签的背景颜色,这是我的数组
Dim Setlab(3) as String
Setlab(0) = Label1.Text
SetLab(1) = Label2.Text
SetLab(2) = Label3.Text
SetLab(3) = Label4.Text
这是我的循环
Dim bcolor As Object
bcolor = Color.Aqua
For i = 0 To Setlab.Length - 1
SetLab(i) = bcolor.ToString
Next
Dim display As String = String.Join(",",SetLab)
Label2.Text = "A = {" & display & "}"
但是当我尝试时输出的是我的标签是Color [Aqua]
Setlab(i) = bcolor
仅对bcolor conversion from color to string is not valid
错误。你能帮我吗?谢谢。
答案 0 :(得分:0)
尝试一下
Dim Setlab(3) as Label
Setlab(0) = Label1
SetLab(1) = Label2
SetLab(2) = Label3
SetLab(3) = Label4
然后您的循环应该是这样
Dim bcolor As Color
bcolor = Color.Aqua
For i = 0 To Setlab.Length - 1
SetLab(i).BackColor = bcolor
Next