Change event of button created through code
Hello, I have this code to create a new button
Code:
Dim NewButton As New Button
frmDownload.Controls.Add(NewButton )
This works.
But I want to change what happens upon clicking NewButton.
It should start an application.
I tried NewButton.Click but that event doesn't exist.
Help?
Re: Change event of button created through code
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim foo As New Button
AddHandler foo.Click, AddressOf FooClick
foo.Text = "bar"
Me.Controls.Add(foo)
End Sub
Private Sub FooClick(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Stop
End Sub
Re: Change event of button created through code
Thanks for the help,
but I forgot to mention something.
I'm working with different new labels created through codes aswell.
So, just to make it simple, I want to get the button to be linked to the new label.
Like this:
Code:
Dim Newlabel As New Label
Dim NewButton As New Button
frmDownload.Controls.Add(Newlabel )
frmDownload.Controls.Add(NewButton )
The new button should then be linked to that new label, so when it's clicked on it'll show the text of the label.