So I'm trying to figure out how to change a buttons text based on having the buttons name as a variable. I already know how to change a buttons text by hardcoding its name like Button1.Text = "hello";
But I want to be able to do something like storing Button1's name in a string called value and then use that string to modify the buttons text so i can use a method for several buttons instead of pasting a huge similar block of code in every buttons method, I just cant seem to figure out how. Any ideas would help.
private void Button3_Click(object sender, EventArgs e)
{
Button obj = sender as Button;
string buttonname = obj.Name;
boxfill(buttonname);
}
private void Button4_Click(object sender, EventArgs e)
{
Button obj = sender as Button;
string buttonname = obj.Name;
boxfill(buttonname);
}
private void Button5_Click(object sender, EventArgs e)
{
Button obj = sender as Button;
string buttonname = obj.Name;
boxfill(buttonname);
}
// this will send the buttons name to boxfill
private void boxfill(string value)
{
// will ideally change the button named with value's
// text to "x"
}