【发布时间】:2016-01-26 03:11:45
【问题描述】:
我正在尝试通过Button_Click 事件(我也动态添加)在我的表单中删除TextBox 控件(动态添加),但我不能找到确切的方法来做到这一点。单击LinkLabel 时,我的文本框将与按钮控件(删除按钮) 一起添加。因此,当动态添加时,我的 textbox.name 将像 textbox_1,textbox_2,textbox_3 并且与它们一起是像 btnDel1,btnDel2,btnDel3 这样的按钮控件(全部放置在面板控件中) .
我的编码是这样的:
Private Sub Button_Click(sender As Object, e As EventArgs)
Dim button As Button = TryCast(sender, Button)
Dim textbox As TextBox = TryCast(sender, TextBox)
'In this case when btnDel1 is clicked, textbox_1 will be removed as well
If button.Name = "btnDel1" Then
PanelOthers.Controls.Remove(button)
End If
End Sub
按钮已成功删除,但我如何也删除文本框?提前致谢。
【问题讨论】: