I'm using VB.net 2003.
I knew that we can create new buttons, new textbox and new label at runtime using code, I would like to know, if we do create those object at runtime, how can we manage their event Such as click event for buttons
Thanks in advanced.

Creating object at Runtime
jsale_endeavor
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=80547&SiteID=1
Best regards,
Johan Stenberg
Soteriologist
Hey Johan.. Thank you for confirming my post
best regards :)
AlexDcosta
crackula
If you want to see the events of object which you create by code you should declare it with "WithEvents" statement.
Friend
WithEvents btnNew As ButtonIf you create your object with such statement, you can see your object on the "Class Name" dropdown menu (left drop down menu on top of the code page), and you can select the method from the "Method Name" dropdown menu (right drop down menu on top of the code page)
Probably you want to create the objects dynamicly, which means you need to declare the objects in a sub, but you can not use WithEvents statement in a sub. 'WithEvents' is not valid on a local variable declaration. What you can do is to adding handler. I don't know if it is the most professional way but I would do this:
Private Sub CreateButtons()For i As Integer = 0 To 2
Dim btn As New Button
btn.Name = "Button" & i.ToString
btn.Text = "Button" & i.ToString
btn.Width = 30
btn.Top = 0
btn.Left = i * 40
Me.Controls.Add(btn)
AddHandler btn.Click, AddressOf buttonClicked 'when the button is clicked, the sub "buttonClicked" will be invoked
Next
End Sub
Private
Sub buttonClicked(ByVal sender As Object, ByVal e As EventArgs)'here, you can do whatever you want to do,
'but probably you need to use some if statements :)..
Dim btn As Button = CType(sender, Button)
MsgBox(btn.Name)
End Sub
I hope it helps.. Success