Setting the same text to multiple labels

fowler1979

New member
Joined
May 16, 2012
Messages
3
Programming Experience
3-5
Hello everybody.

I couldn't quite found anything related to a thing that could be simple:

I have 12 labels and I need to assign them the same tooltip message. I am trying this:
The labels start lbl1, lbl2, lbl3, lbl4, etc...

VB.NET:
for z=1 to 12
tolDicas.SetToolTip(lbl+z, cntMsgLnk)
next

I have other labels, so I do not want to use the
VB.NET:
[B]for each control in me.controls[/B]
....

It's this possible?
Thank you
 
If you need to use code:
Me.Controls("lbl" & z.ToString) will get you the control by name.
In designer you can select multiple controls and set common properties for all.
 
Nevermind, I've managed to do it... I just needed to work my brain out a little harder...

For shrZ As Short = 1 To 12
Dim objLabels As Label = DirectCast(Me.Controls.Find("lbl" & shrZ.ToString(), True)(0), Label)
tolDicas.SetToolTip(DirectCast(objLabels, Label), cntMsgLnk)
Next
 
Instead of search with Find method you can also access the Controls collection these controls belong to directly, for instance Panel1.Controls or similar.
 
Back
Top