The code below works as expected for me. I create a Form , add a
button named Button1 to it and subscribe to its click event. Then in
the click handler I dynamically add another button every time Button1
is clicked.
Public Class Form1
Dim testButton As Button
Dim a As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Me.testButton = New Button()
Me.testButton.Name = String.Format("test{0}", a)
Me.testButton.Location = New Point(a * 100, 10)
a += 1
AddHandler testButton.Click, AddressOf Test_Click
Me.Controls.Add(Me.testButton)
End Sub
Private Sub Test_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim c As Control = CType(sender, Control)
MessageBox.Show(c.Name)
End Sub
End Class
====================
Clay Burch
Syncfusion, Inc.
GAZ - 20 Jul 2007 11:06 GMT
Thanks for the answer. Problem was not in the code, it was in the event
declaration of the control. The event declaration was missing the ByVal
sender as Object bit.
Thanks,
GAZ
> The code below works as expected for me. I create a Form , add a
> button named Button1 to it and subscribe to its click event. Then in
[quoted text clipped - 24 lines]
> Clay Burch
> Syncfusion, Inc.