using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool b = true;
int [] Nmu=new int[4];
int Floor;
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1;
Floor = 0;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1;
Floor = 1;
}
private void button3_Click(object sender, EventArgs e)
{ timer1.Enabled = true;
timer1.Interval = 1;
Floor = 2; }
private void button4_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1;
Floor = 3; } private void timer1_Tick(object sender, EventArgs e)
{
switch (Floor)
{
case 0:
Nmu[0] = button1.Top; break;
case 1:
Nmu[1] = button2.Top; break;
case 2:
Nmu[2] = button3.Top; break;
case3:
Nmu[3] = button4.Top; break;
}
if (b && textBox2.Top > Nmu[Floor])//向上运动
{
textBox2.Top--;
if (textBox2.Top <= textBox1.Top)
b = false;
}
if (textBox2.Top < Nmu[Floor])//向下运动
{
if (!b && textBox2.Top + textBox2.Height <= textBox1.Top + textBox1.Height)
{
textBox2.Top++;
if (textBox2.Top + textBox2.Height > textBox1.Top + textBox1.Height)
b = true;
}
} }
}
}
注:textBox1(楼),textBox2(电梯),button1(1楼的按钮),button2(2楼的按钮),button3(3楼的按钮)button3(4楼的按钮)
。
问题:当textBox2(电梯)向上运动的时候,如果按到button2和button4,电梯移动到button2停1秒钟(不按到的按钮就不停),再继续向下button4移动,
同理:当textBox2(电梯)向下运动的时候,如果按到button3,电梯移动到button3停1秒钟(不按到的按钮就不停),再继续向下button1移动,哪位好心的高手帮我实现一下这个功能,万分感谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货