是否可以使用变量的值在特定控件中进行访问?
Is possible access in a specific control using the value of a variable?
我需要创建一个函数,通过变量 "number" 指定我要更改颜色的控件的编号。
Private Function match_color(partita, number)
If partita = "W" Then
MetroTile1.BackColor = Color.Green 'this is a specific control
ElseIf partita = "D" Then
ElseIf partita = "L" Then
End If
End Function
例如我的目标是访问控制编号 2,所以我调用 match_color
函数:
match_color("D",2)
而变色控件的个数是MetroTile2.BackColor = Color...
不知道有没有讲清楚,简单来说就是变量"number"指定要改变颜色的控件的编号
为什么您的业务逻辑取决于控件在其父控件中的编号?这是毫无意义且容易出错的。话虽如此,您可以使用 Controls.Find
:
Dim controls = Me.Controls.Find("MetroTile" & number, True) ' False if not recursive
If controls.Length > 0 Then
controls(0).BackColor = Color.Green ' or use a loop if you expect multiple
End If
我需要创建一个函数,通过变量 "number" 指定我要更改颜色的控件的编号。
Private Function match_color(partita, number)
If partita = "W" Then
MetroTile1.BackColor = Color.Green 'this is a specific control
ElseIf partita = "D" Then
ElseIf partita = "L" Then
End If
End Function
例如我的目标是访问控制编号 2,所以我调用 match_color
函数:
match_color("D",2)
而变色控件的个数是MetroTile2.BackColor = Color...
不知道有没有讲清楚,简单来说就是变量"number"指定要改变颜色的控件的编号
为什么您的业务逻辑取决于控件在其父控件中的编号?这是毫无意义且容易出错的。话虽如此,您可以使用 Controls.Find
:
Dim controls = Me.Controls.Find("MetroTile" & number, True) ' False if not recursive
If controls.Length > 0 Then
controls(0).BackColor = Color.Green ' or use a loop if you expect multiple
End If