c# - RadioButton.Checked issue -
so having bit of issue piece of code class of mine. know seems rather elementary life of me not sure why can't work.
essentially have 6 radio buttons , depending on 1 selected want assign value int variable. want return value winform else.
but reason returns 0.
some appreciated.
thank in advance..
int x = 0; public int selectiondie1() { if (die1_1.checked) x = 1; if (die1_2.checked) x = 2; if (die1_3.checked) x = 3; if (die1_4.checked) x = 4; if (die1_5.checked) x = 5; if (die1_6.checked) x = 6; return x; } i add if change void no return value , place label display value of x on buttonclick, still returns 0.
i have tried using 1 radiobutton , see if work, nothing @ all.
when set x = 1000; , return works fine, has radio buttons
thank you
if understand correctly, attempting use variable x in other form. need use direct result of selectiondie1 function.
public int selectiondie1() { if (die1_1.checked) return 1; else if (die1_2.checked) return 2; ... else throw new exception("there no item checked"); } this way there no variable keep track of, or accessed outside location.
the other issue creating form , checking selected item (if comment correct). need first create , show form, give user time choose option, , function call (which might happen on user selection, form close, button press, etc).
Comments
Post a Comment