Home All Groups Group Topic Archive Search About

Handling Events for Dynamically Created Controls

Author
23 May 2005 1:07 AM
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
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
23 May 2005 1:16 AM
Armin Zingler
"Nathan Sokalski" <njsokal***@hotmail.com> schrieb
>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
Author
23 May 2005 12:03 PM
Herfried K. Wagner [MVP]
"Nathan Sokalski" <njsokal***@hotmail.com> schrieb:
>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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>