Hallo zusammen,
ich generiere dynamisch, je nach dem wie viele ich brauche, Labels. Wie
bekomme ich das hin das ich im nachhinein diese benutzen kann? oder
andersherum, wie übergebe ich dem Eventhandler Werte?
AddKey_form()
Zu erst werden die Labels erzeugt
lbn
Eventhandler
Oder gibt es einen andern Weg diese Labels zu benutzen?
1 | Private Sub AddKey_form(ByVal count As Long)
|
2 | Dim xPos As Integer = 0
|
3 | Dim yPos As Integer = 0
|
4 | Dim n As Long = 0
|
5 |
|
6 | Dim lbnArray(CInt(count)) As System.Windows.Forms.Label
|
7 | For i As Integer = 0 To CInt(count - 1)
|
8 | lbnArray(i) = New System.Windows.Forms.Label
|
9 | Next i
|
10 |
|
11 | xPos = 12
|
12 | yPos = 26
|
13 | n = 0
|
14 |
|
15 | While (n < count)
|
16 | With (lbnArray(CInt(n)))
|
17 | If count Mod 2 = 0 Then
|
18 | If (n = Math.Round(count / 2, 0)) Then
|
19 | xPos = 156
|
20 | yPos = 26
|
21 | End If
|
22 | Else
|
23 | If (n = Math.Round(count / 2, 0) + 1) Then
|
24 | xPos = 156
|
25 | yPos = 26
|
26 | End If
|
27 | End If
|
28 | .BackColor = Color.White
|
29 | .ForeColor = Color.Black
|
30 | .TextAlign = ContentAlignment.MiddleLeft
|
31 | .Name = "lbn" & n + 1
|
32 | .Tag = n + 1
|
33 | .Width = 90
|
34 | .Height = 19
|
35 | .Left = xPos
|
36 | .Top = yPos
|
37 | ' Add label to a Panel:
|
38 | GroupBox4.Controls.Add(lbnArray(CInt(n)))
|
39 | AddHandler .TextChanged, AddressOf Me.lbn
|
40 | yPos = yPos + 32
|
41 | n = CByte(n + 1)
|
42 | End With
|
43 | End While
|
44 |
|
45 | End Sub
|
46 |
|
47 | Public Sub lbn(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.TextChanged
|
48 | Dim lbnarray As Label = CType(sender, Label)
|
49 | lbnarray.text = "Text"
|
50 |
|
51 | End Sub
|