我在WinForm中放置了FlowLayoutPanel
并创建了一个名为ContactW
通过循环,我在FlowLayoutPanel
填充了几个ContactW
个对象
For index = 0 To 99
Dim Contact As New ContactW.BaseContactW()
Contact.Tag = index
'Here I could set properties
'....
AddHandler Contact.ContactClickEvt, AddressOf GenericClick
flp_ContaninerContacts.Controls.Add(Contact)
Next
GenericClick
获取ContactW
对象,我可以修改它的属性
Public Sub GenericClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cwa As ContactW.BaseContactW = CType(sender, ContactW.BaseContactW)
MessageBox.Show("you have clicked " & CType(CType(sender, System.Object).Tag, String))
cwa.ContactName = "Robert"
End Sub
但我想使用索引或Tag来修改ContactW
的属性,例如:
Contact(21).ContactName = "Julia"
Contact(21).ContactAge = 35
Contact(21).ContactStatus = "Married"
我怎么能实现这个目标?
答案 0 :(得分:1)
首先添加控件的Controls
集合是一个集合,因此您只需像对待任何其他集合一样对其进行索引。