更改循环中数组元素的背景色

时间:2019-02-20 05:51:29

标签: arrays vb.net loops colors tostring

我正在尝试使用循环更改存储在数组中的标签的背景颜色,这是我的数组

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错误。你能帮我吗?谢谢。

1 个答案:

答案 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