通过在下一个循环中进行编码,我已经创建了按钮和文本框,结果
'T(x).Name = "text_1"
'T(x).Name = "text_2"
'T(x).Name = "text_3"
'....
'B(x).Name = "button_1"
'B(x).Name = "button_2"
'B(x).Name = "button_3"
'...
而且我想获得textbox属性,当我单击按钮时,我可以在单击时获得按钮属性,button_1.Name.ToString 但是我无法获得text_1,2,3 ....属性。
我通过拆分函数button_1.Name.ToString做了一些技巧,并获取了最后一个数字并将其添加到文本框名称中,例如,"text_" & button_1.Name.ToString但是我无法将此字符串转换为对象。
更新资料
这是我用来在循环中加载控件的代码:
C_A_TEXT(x) = New TextBox()
C_A_TEXT(x).Dock = System.Windows.Forms.DockStyle.Fill
C_A_TEXT(x).Location = New System.Drawing.Point(270, 5)
C_A_TEXT(x).Margin = New System.Windows.Forms.Padding(0)
C_A_TEXT(x).Size = New System.Drawing.Size(70, 27)
C_A_TEXT(x).TabIndex = 5
C_A_TEXT(x).Name = "NEW_RECHARGE_COUNT_TEXT_" & x
更新2
这是更多代码:
AddHandler C_A_BUTTONS(x).Click, AddressOf C_A_BUTTON
Private Sub C_A_BUTTON(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim thisButton As Button = sender Dim A = CType(Me.Controls("NEW_RECHARGE_COUNT_TEXT_1"), TextBox)
MsgBox(A.Text.ToString) 'Error!
End Sub
慕斯709654
慕标琳琳
HUH函数