vb.net 像 VB6 一样使用控件数组
先新加一个类文件把下面的代码复制上去
Public Class indextest
Private uIndex as int16 ‘像VB6一样用来保存对像的index值
Public Property Index As Int16
Get
Index = uIndex
End Get
Set(ByVal value As Int16)
uIndex = value
End Set
End Property
Public Sub New(Byval index As Int16)
uIndex=index
End Sub
Public Event StateEvent(ByVal Index As Int16, ByVal s As String)’声名事件,
参数可以自已来加改,看你要传什么数据
Public Sub onStateEvent(ByVal value As String) '触发事件函数
’因没有实现内部代码,所以写了一个外部过程来触发事件。
RaiseEvent StateEvent(uIndex, value) '触发事件,在须要触发
的地方加入代码就行了
End Sub
end class
在 From 中 加入一 Button
代码如下:
Public Class Form1
Private mindextest(20) As indextest
Public Sub ProcessLeave(ByVal index As Int16, ByVal s As String)
'运行自已的代码
Debug.Print(index & s)
MsgBox(index & s)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Int16 = 0
mindextest(i) = New indextest(i) ‘实例化数组控件对像
AddHandler mindextest(i).StateEvent,AddressOf ProcessLeave ’注册
评论2