Resimde görüldüğü gibi formumuza 5 buton 5 label 1 textbox 3 picturebox ekliyoruz
ilk picturebox asansör diğer ikiside uzatılmış olan beyaz çubuklar.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a;
private void button5_Click(object sender, EventArgs e)
{
a = 1;
timer1.Start();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.BackColor = Color.Red;
textBox1.Text = ("Meşgul");
}
private void button4_Click(object sender, EventArgs e)
{
a = 2;
timer1.Start();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.BackColor = Color.Red;
textBox1.Text = ("Meşgul");
}
private void button3_Click(object sender, EventArgs e)
{
a = 3;
timer1.Start();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.BackColor = Color.Red;
textBox1.Text = ("Meşgul");
}
private void button2_Click(object sender, EventArgs e)
{
a = 4;
timer1.Start();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.BackColor = Color.Red;
textBox1.Text = ("Meşgul");
}
private void button1_Click(object sender, EventArgs e)
{
a = 5;
timer1.Start();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.BackColor = Color.Red;
textBox1.Text = ("Meşgul");
}
private void timer1_Tick(object sender, EventArgs e)
{
if (a == 1)
{
if (pictureBox1.Top > button5.Top)
{
pictureBox1.Top -= 1;
}
else if (pictureBox1.Top < button5.Top)
{
pictureBox1.Top += 1;
}
else
{
timer1.Stop();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
textBox1.BackColor = Color.Green;
textBox1.Text = ("Uygun");
}
}
if (a == 2)
{
if (pictureBox1.Top > button4.Top)
{
pictureBox1.Top -= 1;
}
else if (pictureBox1.Top < button4.Top)
{
pictureBox1.Top += 1;
}
else
{
timer1.Stop();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
textBox1.BackColor = Color.Green;
textBox1.Text = ("Uygun");
}
}
if (a == 3)
{
if (pictureBox1.Top > button3.Top)
{
pictureBox1.Top -= 1;
}
else if (pictureBox1.Top < button3.Top)
{
pictureBox1.Top += 1;
}
else
{
timer1.Stop();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
textBox1.BackColor = Color.Green;
textBox1.Text = ("Uygun");
}
}
if (a == 4)
{
if (pictureBox1.Top > button2.Top)
{
pictureBox1.Top -= 1;
}
else if (pictureBox1.Top < button2.Top)
{
pictureBox1.Top += 1;
}
else
{
timer1.Stop();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
textBox1.BackColor = Color.Green;
textBox1.Text = ("Uygun");
}
}
if (a == 5)
{
if (pictureBox1.Top > button1.Top)
{
pictureBox1.Top -= 1;
}
else if (pictureBox1.Top < button1.Top)
{
pictureBox1.Top += 1;
}
else
{
timer1.Stop();
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
textBox1.BackColor = Color.Green;
textBox1.Text=("Uygun");
}
}
if (pictureBox1.Top <= 50)
{
label5.BackColor = Color.Red;
}
else if (pictureBox1.Top > 50)
{
label5.BackColor = Color.MistyRose;
}
else
{
label5.BackColor = Color.MistyRose;
}
if (pictureBox1.Top <= 100 && pictureBox1.Top > 50)
{
label4.BackColor = Color.Red;
}
else if (pictureBox1.Top > 100)
{
label4.BackColor = Color.MistyRose;
}
else
{
label4.BackColor = Color.MistyRose;
}
if (pictureBox1.Top <= 150 && pictureBox1.Top > 100)
{
label3.BackColor = Color.Red;
}
else if (pictureBox1.Top > 150)
{
label3.BackColor = Color.MistyRose;
}
else
{
label3.BackColor = Color.MistyRose;
}
if (pictureBox1.Top <= 200 && pictureBox1.Top > 150)
{
label2.BackColor = Color.Red;
}
else if (pictureBox1.Top > 200)
{
label2.BackColor = Color.MistyRose;
}
else
{
label2.BackColor = Color.MistyRose;
}
if (pictureBox1.Top <= 250 && pictureBox1.Top > 200)
{
label1.BackColor = Color.Red;
}
else if (pictureBox1.Top > 250)
{
label1.BackColor = Color.MistyRose;
}
else
{
label1.BackColor = Color.MistyRose;
}
}
}
}