Advertisement
Advertisement
| 06.09.2008 at 03:47AM PDT, ID: 23468562 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: |
Dim Labels() As Label
Sub AddMoreLabels(ByVal NewX As Integer, ByVal NewY As Integer)
Try
If Labels Is Nothing Then
Labels(0) = New Label
Me.Controls.Add(Labels(UBound(Labels) - 1))
AddHandler Labels(UBound(Labels) - 1).Click, AddressOf Labels_Click
Labels(UBound(Labels) - 1).Name = "Lbl(" & UBound(Labels) - 1 & ")"
Labels(UBound(Labels) - 1).Location = New System.Drawing.Point(NewX, NewY)
Else
ReDim Preserve Labels(UBound(Labels))
Labels(UBound(Labels) - 1) = New Label
Me.Controls.Add(Labels(UBound(Labels) - 1))
AddHandler Labels(UBound(Labels) - 1).Click, AddressOf Labels_Click
Labels(UBound(Labels) - 1).Name = "Lbl(" & UBound(Labels) - 1 & ")"
Labels(UBound(Labels) - 1).Location = New System.Drawing.Point(NewX, NewY)
Labels(UBound(Labels) - 1).Visible = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Labels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'See below for GetIndex code.
MsgBox("Hello there from: " & GetIndex(Sender))
End Sub
'This function returns the "Index" of an array. Ie. If Sender is Lbl(5) it
'will return 5 (See Labels_Click for Example)
Function GetIndex(ByVal Sender As System.Object) As Integer
'I used "Pos" and "Name just to enhance readability
Dim Name As String = DirectCast(Sender, Control).Name
Dim Pos As Integer = InStr(1, Name, "(") + 1
Return CInt(Mid(Name, Pos, Len(Name) - Pos))
End Function
|