How do I manipulate control (Label, Text, Button etc) in C #?

0

I have a code where according to the result string of numbers I assign to the Label / Label a corresponding color, but I would like to reduce that code:

to a reduced code (understanding the second line is not correct):

    
asked by Mauro Rivera 04.12.2017 в 19:59
source

1 answer

1

You can use the property Controls of the form to reference controls by name:

this.Controls["lblNumero" + resultado].ForeColor = // ...

Take into account that the instance that returns you is of type Control , so if you need to work with a specific property at Label , you would have to make an explicit cast. But in this case, you only need access to the property ForeColor which is a property common to all controls, so the cast is not necessary.

    
answered by 04.12.2017 / 20:14
source