用c#制作一个简单的电梯系统,当你通过输入楼层号选择一个楼层时,电梯就会到这个楼层。
下一阶段是使用按钮选择楼层。问题是当电梯到达用户要求的楼层时,程序不接受按钮的输入。
这是我必须调用电梯运动并打开计时器的代码:
private void liftOneMove()
{
if ((liftOne.Direction == 1) && (lift1.Value <= 40)) // while lifts going up and floor less/equal to 40
{
timer1.Enabled = true;
}
}
这是计时器内的代码:
private void timer1_Tick(object sender, EventArgs e)
{
lift1.Value++;
liftOne.CurrentFloor = lift1.Value;
lblLift1Flr.Text = "" + lift1.Value;
if (liftOne.FloorRequests.Exists(element => element == lift1.Value))
{
RbLift1.Checked = true;
lblLift1Current.Text = "Doors opening";
//Need to pause the timer here to allow user to select a floor
liftOne.FloorRequests.Remove(lift1.Value);
if(liftOne.FloorRequests.Count == 0)
{
liftOne.Direction = 2;
timer1.Enabled = false;
MessageBox.Show("Floor Requests " + liftOne.FloorRequests.Count);
}
}
}