3 Replies - 2205 Views - Last Post: 05 July 2011 - 12:10 AM Rate Topic: -----

#1 Ellicode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-July 11

how to define a radio button in C# (first time on this forum)

Posted 04 July 2011 - 10:39 PM

 int potion = int.Parse(rdiobtnpotion.Checked);
        if (rdiobtnpotion = true)
        {
            int potion = 40;
        }
        else
        {
            int potion = 0;
        }
        int baron = int.Parse(rdiobtnbaron.Checked);
        if (rdiobtnbaron = true)
        {
            int baron = 40;
        }
        else
        {
            int baron = 0;
        }


what im trying to do here is say that if rdiobtnpotion is checked, then int potion will be 40, if not it will be 0, same thing with rdiobtnbaron. what am i doing wrong? ill attach the file.

Is This A Good Question/Topic? 0
  • +

Replies To: how to define a radio button in C# (first time on this forum)

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4334
  • View blog
  • Posts: 12,130
  • Joined: 18-April 07

Re: how to define a radio button in C# (first time on this forum)

Posted 04 July 2011 - 10:45 PM

No need to parse the checked property of the button, it is boolean for a reason. Simply use it in the if statement...

int potion = 0;

if (rdiobtnbaron.Checked) {
   potion = 40;
}



Set the variable to 0 and then test the radio button. If it is checked, change its value. Otherwise it will be left as 0.

:)
Was This Post Helpful? 0
  • +
  • -

#3 Ellicode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-July 11

Re: how to define a radio button in C# (first time on this forum)

Posted 04 July 2011 - 11:22 PM

View PostMartyr2, on 04 July 2011 - 10:45 PM, said:

No need to parse the checked property of the button, it is boolean for a reason. Simply use it in the if statement...

int potion = 0;

if (rdiobtnbaron.Checked) {
   potion = 40;
}



Set the variable to 0 and then test the radio button. If it is checked, change its value. Otherwise it will be left as 0.

:)

int potion = 0;
int baron = 0;
if ( rdiobtnpotion.Checked)
        {
            int potion = 40;
        }
        

        if (rdiobtnbaron.Checked)
        {
            int baron = 40;
        }
        


thanks for the reply :D! its giving me the following errors tho :(, "The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -="
it says this twice, then it says "'potion conflicts with the declaration 'WpfApplication1.Window1.potion'". not to sure what these error messages mean :(...


**edit**
i got rid of the last error by deleting int from potion and baron like u did, i didnt see that u did that xD, but the first 2 remain, and the error lies with ".Checked" which is in parentheses after the if statement

This post has been edited by Ellicode: 04 July 2011 - 11:26 PM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: how to define a radio button in C# (first time on this forum)

Posted 05 July 2011 - 12:10 AM

Checked is an event. IsChecked is the property.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1