我正在使用vb.net窗口应用程序,我必须通过字符串名称在窗口中找到Control。为此,我使用了以下代码: -
Dim lbl As New Label
Dim st As String
st = "lblFeeder" + i.ToString()
lbl = CType(Me.Controls(st), Label)
lbl.Text = dt.Rows(37)("AnaTagValue")
但是当程序运行时会出现错误
"Object reference not set to an instance of an object."
在位置
"lbl.Text = dt.Rows(37)("AnaTagValue")"
当我调试它时,我发现该位置“没什么” “lbl = CType(Me.Controls(st),Label)”
我该如何解决这个问题?