在VB .NET中查找动态添加的控件
|
我创建了一个新的标签页,并在其中添加了一个富文本框:
Private Sub AddTab(ByVal ctrl As TabControl, _
ByVal text As String)
If Me.InvokeRequired Then
Me.Invoke(New AddTabDelegate(AddressOf AddTab), _
New Object() {ctrl, text})
Return
End If
Dim NewTab As New TabPage
NewTab.Name = \"OutputTab\" & outputs.Item(outputs.Count - 1)
NewTab.Text = \"Domain\"
Dim NewTextbox As New RichTextBox
NewTextbox.Name = \"OutputTextbox\" & outputs.Item(outputs.Count - 1)
ctrl.Controls.Add(NewTab)
NewTab.Controls.Add(NewTextbox)
End Sub
现在,我尝试在代码中的其他位置访问richtextbox:
Dim NewTextbox As RichTextBox
NewTextbox = Me.Controls.Item(\"OutputTextbox\" & current_output)
debug.print(NewTextbox.name)
我收到以下错误:
A first chance exception of type \'System.NullReferenceException\' occurred in program.exe
我知道名称是严格的,因为我已经在create方法中打印了名称,并且已经在尝试访问它的代码中打印了名称字符串。
因此,从外观上看,.Item()
不是访问控件的正确方法。
那么如何访问动态创建的控件呢?
没有找到相关结果
已邀请:
1 个回复
才改隘瘁
进行递归搜索,但是在这种情况下,由于您知道带有
的容器,因此执行如下所示的操作会更有效。 尝试