Kent Posted December 4, 2003 Posted December 4, 2003 I use VB.NET How do I make a control array, like I did in VB 6.0. I have 100 labels I need to do the same thing "on click" but with diffriend input. Quote
*Experts* Bucky Posted December 4, 2003 *Experts* Posted December 4, 2003 Subroutines have a "Handles" statement that is placed after the parameter declarations. Events can be comma-delimited so that one sub handles many events. Like this: Public Sub Labels_Click(sender As Object, e As EventArgs) Handles Label1.Click, Label2.Click, Label3.Click ' Event handler here End Sub Of course, if you don't want to type out all the event handlers, place all the Label controls in a container (a frame or a panel) and on the Form's load event add the handler for all the controls. Dim ctl As Control For Each ctl in Panel1.Controls AddHandler ctl.Click, AddressOf Labels_Click Next Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Kent Posted December 4, 2003 Author Posted December 4, 2003 Thank you for your help. I'll try that. Quote
Kent Posted December 5, 2003 Author Posted December 5, 2003 How do I get the text property value of the pressed label into the label_click event, so I'll be able to know wich one is pressed? How do I pass the variable? Quote
*Experts* mutant Posted December 6, 2003 *Experts* Posted December 6, 2003 Cast the sender object into a Label object: DirectCast(sender, Label).Text = "something" Now you will be able to access the properties of the sender so you can figure out which control it was. Quote
Kent Posted December 6, 2003 Author Posted December 6, 2003 Wow, you have an answer to everything, havn't you. Thanks man. That's just what I needed. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.