Using Dynamically Created Objects (Labels)

jtstanish

Newcomer
Joined
Dec 10, 2004
Messages
10
I have created an array of label objects and placed them on a form in a VB .NET application. How do I generate .CLICK actions for these objects?
Also can I have all of them call the same subroutine on click passing the control itself. In this way I can change the control's properties when it is clicked. Thanks!
 
Use something like

AddHandler Me.Controls("Button1").Click, AddressOf Button2_Click
AddHandler Me.Controls("Button2").Click, AddressOf Button2_Click
AddHandler Me.Controls("Button3").Click, AddressOf Button2_Click

the rest you should be able to fighre out if you look at the built in help.....
 
Thanks ... But I need more detail please

What is "AddressOf Button2_Click" The name of a subroutine? Sorry, I'm very new to VB .NET ...

donnacha said:
Use something like

AddHandler Me.Controls("Button1").Click, AddressOf Button2_Click
AddHandler Me.Controls("Button2").Click, AddressOf Button2_Click
AddHandler Me.Controls("Button3").Click, AddressOf Button2_Click

the rest you should be able to fighre out if you look at the built in help.....
 
Button2_click would be a valid event handler for a button click event, really just a subroutine with a specific method signature.
Visual Basic:
'should be similar to
private sub Button2_click(sender as object, e as Eventargs)
'handle button click here
end sub
 
We are not here to do the work for you, you must read somestuff yourself, you are asking questions that is given in the VS help or command syntax, please read this info.
 
Back
Top