How to built an elevator of 5 floors?
Hello. I have so far tried to move the pictureBox1 that is supposed to be the chaimber of the elevator up and down in the Form (form1 in the code), but no luck so far. My idea was to produce the motion originally and then implement the neccesary if-else satements so it will work as an eleavator. I haven't got any compiled errors but it's not only moving, but also the Form1 is not appearing when i execute it throuth the compiler (Visiual studio 2015). It is only showing the Messageboxes i myself put so i debug it.
Nilesh ShahPosted Feb 8, 2017, 12:54 PM
Gerasimos MoschopoulosPosted Feb 8, 2017, 1:11 PM
Gerasimos MoschopoulosPosted Feb 7, 2017, 12:17 AM
Nilesh ShahPosted Feb 6, 2017, 11:54 PM
Gerasimos MoschopoulosPosted Feb 6, 2017, 10:43 PM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
//using System.Timers;
namespace Elevator1
{
public partial class Form1 : Form
{
Timer timer = new Timer();
bool anodos;
bool kathodos;
int floor;
int X;
int Y;
private void CreateMotion(Timer t)
{
if (anodos)
{
MessageBox.Show("Y=" + (panel1.Location.Y).ToString());
MessageBox.Show("Y=" + Y.ToString());
MessageBox.Show("t=" + t.Interval.ToString());
do
{
// var X = 285;
//var Y = 847;
//Y = 847;
//timer.Enabled = true;
//Y = Y - t.Interval;
//MessageBox.Show("Y=" + (panel1.Location.Y).ToString());
//MessageBox.Show("Y=" + Y.ToString());
//MessageBox.Show("t=" + t.Interval.ToString());
//X = 285;
//newPosition = oldPosition + (elapsedTime * velocity)
timer.Tick += new EventHandler(timer1_Tick);
// System.Threading.Thread.Sleep(500);
//tab1text.Invoke(new Action(delegate () { tab1text.Text = inputLine; }));
// System.Threading.Thread.Sleep(500);
//panel1.Invoke(new Action(delegate () { panel1.Location = new Point(panel1.Location.X, panel1.Location.Y-1); }));
//panel1.Location = new Point(panel1.Location.X, panel1.Location.Y-1);
//groupBox1.Location = new Point(groupBox1.Location.X, groupBox1.Location.Y - 1);
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y-1 );
pictureBox1.Refresh();
//MessageBox.Show("Y=" + (panel1.Location.Y).ToString());
if (pictureBox1.Location.Y == 822)
{
floor = 0;
MessageBox.Show("Y=" + (panel1.Location.Y).ToString());
MessageBox.Show("The elevator starts");
}
else if (pictureBox1.Location.Y == 703)
{
floor = 1;
MessageBox.Show("The elevator is in the first floor");
}
else if (pictureBox1.Location.Y == 521)
{
floor = 2;
MessageBox.Show("The elevator is in the second floor");
}
else if (pictureBox1.Location.Y == 359)
{
floor = 3;
MessageBox.Show("The elevator is in the third floor");
}
else if (pictureBox1.Location.Y == 197)
{
floor = 4;
MessageBox.Show("The elevator is in the fourth floor");
}
else if (pictureBox1.Location.Y == 52)
{
floor = 5;
MessageBox.Show("The elevator is in the fifth floor");
kathodos = true;
anodos = false;
}
/*
Y = Y - t.Interval;
X = 285;
//newPosition = oldPosition + (elapsedTime * velocity)
System.Threading.Thread.Sleep(500);
panel1.Location = new Point(panel1.Location.X, panel1.Location.Y);
panel1.Update();*/
//Y--;
} while (anodos);
}
else if (kathodos)
{
do
{
// Y++;
timer.Tick += new EventHandler(timer1_Tick);
timer.Enabled = true;
//Y = Y + timer.Interval;
// System.Threading.Thread.Sleep(500);
//panel1.Invoke(new Action(delegate () { panel1.Location = new Point(panel1.Location.X, panel1.Location.Y-1); }));
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y+1);
pictureBox1.Refresh();
if (pictureBox1.Location.Y == 822)
{
floor = 0;
kathodos = false;
anodos = true;
}
else if (pictureBox1.Location.Y == 703)
{
floor = 1;
}
else if (pictureBox1.Location.Y == 521)
{
floor = 2;
}
else if (pictureBox1.Location.Y == 359)
{
floor = 3;
}
else if (pictureBox1.Location.Y == 197)
{
floor = 4;
}
else if (pictureBox1.Location.Y == 52)
{
floor = 5;
anodos = false;
kathodos = true;
}
} while (kathodos);
}
}
public Form1()
{
InitializeComponent();
anodos = true;
kathodos = false;
timer.Enabled = true;
timer.Interval = 1000;
//timer.Tick += new EventHandler(timer1_Tick);
X = 405;
Y = 822;
floor = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
timer.Enabled = true;
timer.Start();
CreateMotion(timer);
}
private void timer1_Tick(object sender, EventArgs e)
{
CreateMotion(timer);
timer.Tick += new EventHandler(timer1_Tick);
}
}
}
Nilesh ShahPosted Feb 6, 2017, 3:28 PM