在循环中更改数组元素的背景色
Change backcolor of array elements in loop
我正在尝试更改使用循环存储到数组中的标签的背景颜色,这是我的数组
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
出错。你能帮我吗?谢谢
试试这个
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
我正在尝试更改使用循环存储到数组中的标签的背景颜色,这是我的数组
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
出错。你能帮我吗?谢谢
试试这个
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