forum

Home / DeveloperSection / Forums / Working with Radio Buttons

Working with Radio Buttons

Royce Roy215809-Feb-2014

I have a program which executes a code in 2 different ways based on the radio button selected(user's choice). My problem is am not able to get what user has selected, meaning the code where it is suppose to execute in different ways based on the radio button selection , that code segment does not execute.

Here is what i have done :-

This is the part where i determine what user has selected from the radio buttons

 public Airplane_Simulation()

           {

            InitializeComponent();

                if (rbZero.Checked==true) //checks whether it is selected

            {

                section = rbZero.Text; //if true assigns it's text to a variable.

            }

            else

            if (rbOne.Checked == true)

            {

                section = rbOne.Text;

            } 

        semaphore = new Semaphore();

        buff = new Buffer();

        btnPnlT1 = new ButtonPanelThread(new Point(40, 5), 50, pnlArrival, false, Color.Red, semaphore, buff, btnGo);

        waitingTakeOff = new waitPanels(new Point(490, 5), 50, pnlTakeOff, false, Color.Green, semaphore, buff,section);

        thread1 = new Thread(new ThreadStart(btnPnlT1.start));

        thread3 = new Thread(new ThreadStart(waitingTakeOff.start));

        thread1.Start();

        thread3.Start();

    }

This is the code which is supposed to execute based on the user choice

 if(section.Equals("0"))  //if the variable match 0 it should this code

                {

                     for (int k = 0; k < 15; k++)

                     {

                    panel.Invalidate();

                    this.movePlane(xDelta, yDelta);

                    Thread.Sleep(delay);

                     }

                }

                else

                    if (section.Equals("1")) //if variable matches 1 it

                                             //should execute this code

                    {

                       for (int k = 0; k < 40; k++)

                      {

                           panel.Invalidate();

                           this.movePlane(xDelta, yDelta);

                           Thread.Sleep(delay);

                        }

I tried assigning the value directly to variable section without taking from a radio button then it worked. So i am sure it's something to do with assigning when using radio buttons.

Thank you for your time.


Updated on 09-Feb-2014

Can you answer this question?


Answer

1 Answers

Liked By