I am currently making searching platform for materials, and I want to make a button with periodic table. what I am doing now is to make every button for the periodic table, and making every click events for each button.
public void bc(string a)
{
if (MainEntry.Text == "")
{
MainEntry.Text = a;
}
else
{
MainEntry.Text = MainEntry.Text + "," + a;
}
}
private void buttonLi_Click(object sender, EventArgs e)
{
bc("Li");
}
private void buttonBe_Click(object sender, EventArgs e)
{
bc("Be");
}
I wonder if there are another option for this. such as, if I press the button, system reads what is written on the button, and use the text on the method. So that I can decrease my code lines.


bc("Li");senderis the button itself so you can modify your code based on that. Eg, you can use theTextto decide what to send based on the button's text, or theTagproperty. All controls have aTagproperty that's used to store extra info