The following tutorial will show How to get the text of selected radiobutton controls.
A RadioButton control provides a round interface to select one option from a number of options. Radio buttons are usually placed in a group on a container control, such as a Panel or a GroupBox, and one of them is selected.
Text property of a RadioButton represents the current text of a RadioButton control.
Solution 1:
1 2 3 4 5 6 7 8 9 10 11 12 |
private void button1_Click(object sender, EventArgs e) //Solution 1 { foreach (Control rb in groupBox1.Controls) { if(((RadioButton)rb).Checked) { label1.Text = rb.Text; } } } |
Solution 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private void button2_Click(object sender, EventArgs e) //Solution 2 { if (radioButton1.Checked) { label1.Text = radioButton1.Text; } else if (radioButton2.Checked) { label1.Text = radioButton2.Text; } else if (radioButton3.Checked) { label1.Text = radioButton3.Text; } else if (radioButton4.Checked) { label1.Text = radioButton4.Text; } else { label1.Text = "Seçim yapın"; } } |
Output: