By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

Using VB 2010, I need to access a label's Tag data (in this case a number) in a label

P: 2
I will have ten labels, each will have a Tag property set to 1 through 10. In each label's click event, I want to be able to access the Tag property without referring directly to the Label's Name. I have tried Me. My. sender, etc. but unable to get something workable. Thank you
Dec 13 '13 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
You mentioned that you have implemented a method that handles the Click Event for all the 10 labels that you want to work with.

This means that you should have a method that looks something like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub labels_Click(sender As Object, e As System.EventArgs) Handles label1.Click, label2.Click,  label3.Click ,label4.Click,  label5.Click, label6.Click, label7.Click, label8.Click, label9.Click, label10.Click
  2.  
  3. End Sub
The sender parameter is the control that fired the event...in other words, it is the Label that was clicked.

From there you should be able to retrieve the content of the label, parse it into an Integer and do your logic.

Expand|Select|Wrap|Line Numbers
  1. Private Sub labels_Click(sender As Object, e As System.EventArgs) Handles label1.Click, label2.Click, label3.Click, label4.Click,  label5.Click, label6.Click, label7.Click, label8.Click, label9.Click, label10.Click
  2.  
  3.   Dim theLabelClicked As Label = DirectCast(sender, Label)
  4.   Dim theInteger As Integer
  5.   Integer.TryParse(theLabelClicked.Text, theInteger)
  6.  
  7.   If theInteger > 0 And theInteger <= 10
  8.     '...Do Processing Of Stuff...
  9.   End If
  10. End Sub
-Frinny
Dec 17 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.