Handling Events for Dynamically Created Controls

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have several Button controls that I created dynamically that I need to
handle the Click events for. How do I specify the event handler for
dynamically created controls? Thanks.
 
Nathan Sokalski said:
I have several Button controls that I created dynamically that I need
to
handle the Click events for. How do I specify the event handler for
dynamically created controls? Thanks.

Use the Addhandler statement.

Armin
 
Nathan Sokalski said:
I have several Button controls that I created dynamically that I need to
handle the Click events for. How do I specify the event handler for
dynamically created controls?

\\\
Private Sub Test()
Dim Button1 As New Button()
With Button1
.Location = New System.Drawing.Point(56, 88)
.Name = "Button1"
.Size = New System.Drawing.Size(144, 48)
.TabIndex = 0
.Text = "Button1"
End With
AddHandler Button1.Click, AddressOf Me.Button_Click
Me.Controls.Add(Button1)
End Sub

Private Sub Button_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
)
MsgBox("Hello World")
End Sub
///
 
Back
Top