Código
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim pcb As New Button : pcb.Tag = "Elektro H." : AddHandler pcb.Click, AddressOf pcb_click : Me.Controls.Add(pcb) End Sub Private Sub pcb_click(sender As System.Object, e As System.EventArgs) MsgBox(sender.tag) End Sub
@Patxiku69
No necesitas a San Google para estas cosas, necesitas fijarte en los posts con chincheta en el foro. y sobretodo usar el buscador del foro, porque no hace mucho pregunté un tema parecido y está en la primera página del foro vaya...
Y bueno, aunque llego tarde a lo de asociar eventos, aquí tienes un código que te habría venido muy bien:
[APORTE] Snippets !! (Posteen aquí sus snippets)
Add controls with events in real-time
Código
Dim chk_() As CheckBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Array_Size As Integer = 5 'change this for the number of controls that will appear ReDim chk_(Array_Size) For chk_num = 0 To Array_Size chk_(chk_num) = New CheckBox chk_(chk_num).Text = "Checkbox " + chk_num.ToString chk_(chk_num).Top = 20 * chk_num Me.Controls.Add(chk_(chk_num)) ' Add a event handler to a subroutine AddHandler chk_(chk_num).CheckedChanged, AddressOf CheckBoxSub Next End Sub Public Sub CheckBoxSub(ByVal sender As Object, ByVal e As System.EventArgs) Dim CheckboxN As CheckBox = CType(sender, CheckBox) If CheckboxN.Checked = True Then MsgBox("Checkbox is checked") Else MsgBox("Checkbox is unchecked") Ens Sub
Handle the same event for various controls
Código
Private Sub Button_Is_Clicked(sender As Object, e As EventArgs) Handles _ Button1.Click, _ Button2.Click, _ Button3.Click Dim Clicked_Button As Button = CType(sender, Button) If Clicked_Button.Name = "Button1" Then ' Things for Button1 ElseIf Clicked_Button.Name = "Button2" Then ' Things for Button2 ElseIf Clicked_Button.Name = "Button3" Then ' Things for Button3 End If Ens Sub
Saludos!