Handling Events for Dynamically Created Controls

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.
 
A

Armin Zingler

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
 
H

Herfried K. Wagner [MVP]

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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top