我有一个程序,它根据选择的单选按钮(用户的选择)以两种不同的方式执行代码。我的问题是无法获取用户选择的内容,这意味着假设基于单选按钮选择以不同方式执行的代码,该代码段不会执行。
这是我所做的:-
这是我确定用户从单选按钮中选择的部分
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();
}
这是应该根据用户选择执行的代码
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);
}
}
我尝试将值直接分配给变量部分,而不从单选按钮中获取,然后它就起作用了。所以我确信这与使用单选按钮时的分配有关。
感谢您的时间。