我有一个LinkLabel
我在我的表单中动态添加的。我LinkLabel
只会在CheckBox
选中 a 时显示。我用它在我的表单LinkLabel
中添加了一个TextBox
,用户最多只能添加5 个 TextBox
。在达到最大值后,LinkLabel
它将被禁用(但尚未添加到我的编码中)。
这是我目前使用的编码。
'This is my CheckBox
Private Sub CheckBoxOthers_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxOthers.CheckedChanged
If CheckBoxOthers.Checked = True Then
PanelOthers.Visible = True 'My TextBox and LinkLabel are inside a Panel
Dim count As Integer = PanelOthers.Controls.OfType(Of Label)().ToList().Count
Dim textbox As New TextBox()
Dim linklabel1 As New LinkLabel()
count = PanelOthers.Controls.OfType(Of TextBox)().ToList().Count
textbox.Location = New System.Drawing.Point(15, 40 * count)
textbox.Size = New System.Drawing.Size(172, 20)
textbox.Name = "textbox_" & (count + 1)
AddHandler textbox.TextChanged, AddressOf TextBox_Changed
PanelOthers.Controls.Add(textbox)
'Adding LinkLabel dynamically
linklabel1.Name = "lnkAddSubj"
linklabel1.Text = "Add Subject"
linklabel1.Location = New Point(300, 3)
AddHandler linklabel1.Click, AddressOf linklabel1_Click
PanelOthers.Controls.Add(linklabel1)
Else
PanelOthers.Visible = False
PanelOthers.Controls.Clear()
End If
End Sub
这是我LinkLabel
点击时添加 TextBox 的事件,最多 5 次,但我还没有添加编码来设置限制
Private Sub linklabel1_Click(sender As Object, e As EventArgs)
Dim count As Integer = PanelOthers.Controls.OfType(Of Label)().ToList().Count
Dim textbox As New TextBox()
count = PanelOthers.Controls.OfType(Of TextBox)().ToList().Count
textbox.Location = New System.Drawing.Point(15, 40 * count)
textbox.Size = New System.Drawing.Size(172, 20)
textbox.Name = "textbox_" & (count + 1)
AddHandler textbox.TextChanged, AddressOf TextBox_Changed
PanelOthers.Controls.Add(textbox)
'So here after LinkLabel clicked 5 times then my LinkLabel will be disabled and I'm trying to do like this but it said LinkLabel1 is not declared
LinkLabel1.Enabled = False
End Sub
如何使LinkLabel
属性能够被设置?我能够编写它的 Click 事件,因为我在我的事件中为它添加了一个处理程序CheckBox
。