Using C# and Windows Forms, i would like to use the name of a Label
as a parameter of another function, like this:
startBox(label_box, "11", Color.Red);
Definition of startBox
:
private void startBox(Label label, string text, Color color) {
label.BackColor = color;
label.Visible = true;
label.Enabled = true;
label.Text = text;
}
But, is there any way to convert an string
to the name of a Label
?
In my case, label_box
is a string
.
ps¹. I need to do this because i have N
Labels
and the name is should be typed by the user.
ps². To Invoke a method using a string
i used the MethodInfo
.
EDIT: The solution using Controls does not apply. In my case, a string is given as an input, if the string is the name of one of the labels the function is called.
Thank you, and sorry for the spelling flaws in English.