Quick question how can I search text inside 60 labels.text
and the label color will change. Thanks in advance and I appreciate the help last time
dim Nc as color = color.RED
dim Oc as color = Color.Black
'' i need to search in multiple labels.text using txt1.text if possible
if txt1.text = label1.text then
laebl1.forecolor = Nc
End IF
Is there an easier way ?
You need to create an list of labels and add all the labels in the array during Form_Load. Then you need to loop thru the array and compare the text of each label with the txt1.Text and change the color of the label if condition matches.
Following is the sample code for this.
This should resolve your issue.
Following the answer provided by
@Chetan_Ranpariya
and translating the code toVB.Net
(with a small tweak) it would be something like this:Basically for this you need a
List of Tuple
which is more efficient since every control has a pair. Inside theFor Each
statement you can include anElse
clause to change the color to another one (I think this is to indicate the user the required fields on a form)Give it a try and let me know your comments