C#电梯系统,暂停
用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);
}
}
}
Making a simple elevator system in c#, got it working for when yuo select a floor by typing in a floor number, the lift then goes to this floor.
The next stage is to select a floor using a button. The problem is when the lift gets to the floor that the user requested, the program does not accept the input from a button..
This is the code i have to call the lift movement and switch the timer on:
private void liftOneMove()
{
if ((liftOne.Direction == 1) && (lift1.Value <= 40)) // while lifts going up and floor less/equal to 40
{
timer1.Enabled = true;
}
}
This is the code within the timer:
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于原型,您可能想做这样的事情,以允许用户选择另一个楼层:
并使用另一个计时器在 5 秒内启用第一个计时器:
在这 5 秒期间,用户可以选择另一个楼层。
As for the prototype, you may want to do something like this to allow the user to select another floor:
and use another timer to enable the first timer in 5 seconds:
During this 5-second period, user can choose another floor.