I have 3 different radio buttons and one label. How to update text on that label when radio is checked?
private void Button_Click(object sender, EventArgs e)
{
foreach (Control item in groupBox1.Controls)
{
if(item.GetType() == typeof(RadioButton))
{
if (((RadioButton)item).Checked)
{
label1.text = obj[item.TabIndex-1].name;
}
}
}
}
I wrote something like that but it is connected to button but i don’t want it to work that way. I’d like to make event connected to all 3 radio buttons but i don’t know how to do that.
You should look in to adding an event for each radio button. Specifically, look at the
CheckedChangedevent.Or as Oded mentioned, use the same event and take advantage of the
senderparameter. They will all point to the same event.