Hello,
I am currently working on Winforms, and I have 3 radio buttons that will have different values.
this is what I have on MainForm.cs, but I want to move this over to another class:
public double RadioValue
{
get
{
if (radioOne.Checked) return 1.56;
if (radioTwo.Checked) return 4.1;
if (radioThree.Checked) return 4.2;
return 0;
}
}
How to bring radio button value to a class.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 25, 2014, 8:39 PM EDT
class Logic
{
public static double RadioValue(bool fR1, bool fR2, bool fR3)
{
if (fR1) return 1.56;
if (fR2) return 4.1;
if (fR3) return 4.2;
return 0;
}
}
The method takes three bools (representing the values of the three radiobuttons).
In the form (example below uses a button to get the double value), you can call the method as shown
private void button1_Click(object sender, EventArgs e)
{
double val = Logic.RadioValue(radioButton1.Checked, radioButton2.Checked, radioButton3.Checked);
label1.Text = val.ToString();
}
You can put all your logic methods in the logic class.
Song Lee49 reputationPosted Oct 26, 2014, 5:35 PM EDT