Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
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?
  • *Experts*
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...