#33 Matěj Andrle
Tak hotovo! Funguje to tak jak požaduji. Mohl by ses na můj výtvor kouknout a říct, co by se dalo vytvořit jinak, elegantněji? (text v labelech bude načítan přes pole z excelovské databaze)
Public Class Form1
Dim seznam_talcitek As New Dictionary(Of String, Button)
Dim seznam_labelu As New Dictionary(Of String, Label)
Dim seznam_checku As New Dictionary(Of String, CheckBox)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 1 To 10
Dim butt As New Button
butt.Height = 20
butt.Width = 20
butt.Left = 5
butt.Top = i * 30 - 30
butt.Text = i
butt.Tag = i
butt.TabIndex = i
seznam_talcitek.Add(butt.TabIndex, butt)
Me.Controls.Add(butt)
AddHandler butt.Click, AddressOf Button_Click
Dim label As New Label
label.Name = i & "a"
label.Height = 30
label.Width = 100
label.Left = 60
label.Top = i * 30 - 30
label.Text = i & " nevím"
label.Tag = i
label.TabIndex = i
seznam_labelu.Add(label.TabIndex, label)
Me.Controls.Add(label)
Dim check As New CheckBox
check.Name = i & "a"
check.Height = 30
check.Width = 100
check.Left = 160
check.Top = i * 30 - 35
check.Text = i & " check"
check.Tag = i
check.TabIndex = i
seznam_checku.Add(check.TabIndex, check)
Me.Controls.Add(check)
Next
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim butt As Button = sender
Dim index As Integer
index = sender.tabindex
If seznam_checku(index).Checked = True Then
Label1.Text = seznam_labelu(index).Text
Else
Label1.Text = "není označen check"
End If
End Sub
End Class