hi,how would i make two panels coming from different directions like elevator closing
two doors.
have a look at this video Year 2 OOP and SE assignment 1: Elevator

i want to make an exact application elevator simulator,can you please tell me or provide me with a code that it can work.

i tried playing around with it but no luck
thanks

This is just a suggestion. Drag 2 panels onto a blank form and set Panel1's Dock in the properties window to Left and Panel2's Dock to right. For visual purposes assing them both colors or add a border.

Next add a button and in the button click event add the following.

Panel1.Width++;
Panel2.Width++;

This will cause the two corresponding sides of the panels to move closer together.

This should help you get started.

For furure reference.. Remember that daniweb users are here to help you but not do the work for you.

Regards

let me give it a try and i will let you know

thanks

hi,i tried it but it doesn't move all the way,i mean they dont move to meet each other like close.

you have to keep clicking it inorder for it move closer.

thanks

What exactly do you want to know?

What code have you written so far?

What video are we supposed to be looking at?

sorry,this is the video link:
http://www.youtube.com/watch?v=htlX7SxhdHM

What exactly do you want to know?

i need to know a code or a guide on how to make the elevator move up and down.

when it moves up to first or second floor,the door should open with a light,
when button 1 or 2 is pressed the elevator should move to the floor and the door should open.

this is what i've been asked to do:

create gui that contains Two request buttons corresponding to the two floors, respectively
•One control panel with two buttons and a display window
•Two display areas that display the status of the elevator, i.e. which floor the elevator currently stays, one is of each floor
•A log button
Task 2: To create a control program that processes the events published by the GUI. That is,
•When any request button is pressed,
othe elevator moves to the corresponding floor
othen the display areas and the display window on the control panel show the corresponding floor number at the same time
•When the floor number buttons on the control panel are pressed,
othe elevator moves to the corresponding floor
othen the display areas and the display window on the control panel show the corresponding floor number at the same time

please help me guys i have create the two buttons but i am stuck on how to make the door and how it should move.

thanks

I just gave you a hint. You will need to code the logic to set the panel location and the logic to determine if the edges of the panels have connected.

Google Moving objects programmatically and Collision detection or something similar.

guys i really need help,i have to finish the project by sunday

thanks

sorry fenrir its just that i am new to these stuff.

here is a project similar project code

    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;
    using System.Media;
    using System.Threading;

    namespace Elevator
    {
        public partial class Form1 : Form
        {
            enum direction
            {
                Up, Down            
            }

            direction which = new direction();
            enum floor
            {
                first,second,third           
            }

            floor goingTo = new floor();
            int liftSpeed ;
            Font myFont = new Font("Arial", 16);
            Bitmap needle;
            int myAngle=0;
            int myRatioUp = 0;
            int myRatioDown = 0;
            Thread motor = null;
            public delegate void driveLift();//delegate to help motor thread
            bool pauseThread = false;// checks if motor thread stopped

            public Form1()
            {
                InitializeComponent();
                bttnDown3.Enabled = false;
                bttnUp1.Enabled = false;
                bttnUp1to3.Enabled = false;
                bttnDown3to1.Enabled = false;
                label4.Text = ("Lift speed interval = 1ms");

            }

            private void Form1_Load(object sender, EventArgs e)
            {
                goingTo = floor.second;
                drawNeedle();
                rotateNeedle();

            }

            public void drawNeedle()
            {
                needle = new Bitmap(5,40);
                Graphics g = Graphics.FromImage(needle);
                g.FillRectangle(Brushes.Red, 0, 0, 5, 40);
                g.FillRectangle(Brushes.Blue, 0, 0, 5, 5);


            }

            private void bttnDown3_Click(object sender, EventArgs e)//third floor
            {
                which = direction.Down;
                goingTo = floor.second;
                bttnDown3.Enabled = false;
                bttnDown3to1.Enabled = false;
                bttnUp2.Enabled = true;
                bttnDown2.Enabled = true;
                pauseThread = false;
                  motor = new Thread(new ThreadStart(runThread));
                 motor.Start();


            }
            private void bttnDown3to1_Click(object sender, EventArgs e)
            {
                which = direction.Down;
                goingTo = floor.first;
                bttnDown3.Enabled = false;
                bttnDown3to1.Enabled = false;
                bttnUp1to3.Enabled = true;
                bttnUp1.Enabled = true;
                pauseThread = false;
                motor = new Thread(new ThreadStart(runThread));
                motor.Start();
            }


            private void bttnDown2_Click(object sender, EventArgs e)//second floor
            {
                which = direction.Down;
                goingTo = floor.first;
                bttnUp2.Enabled = false;
                bttnDown2.Enabled = false;
                bttnUp1.Enabled = true;
                bttnUp1to3.Enabled = true;
                pauseThread = false;
                motor = new Thread(new ThreadStart(runThread));
                motor.Start();

            }

            private void bttnUp2_Click(object sender, EventArgs e)//second floor
            {
                which = direction.Up;
                goingTo = floor.third;
                bttnUp2.Enabled = false;
                bttnDown2.Enabled = false;
                bttnDown3.Enabled = true;
                bttnDown3to1.Enabled = true;
                pauseThread = false;         
                motor = new Thread(new ThreadStart(runThread));
                motor.Start();
            }

            private void bttnUp1_Click(object sender, EventArgs e)//first floor
            {
                which = direction.Up;
                goingTo = floor.second;
                bttnUp1.Enabled = false;
                bttnUp1to3.Enabled = false;
                bttnUp2.Enabled = true;
                bttnDown2.Enabled = true;
                pauseThread = false;            
                motor = new Thread(new ThreadStart(runThread));
                motor.Start();

            }
            private void bttnUp1to3_Click(object sender, EventArgs e)
            {
                which = direction.Up;
                goingTo = floor.third;
                bttnUp1.Enabled = false;
                bttnUp1to3.Enabled = false;
                bttnDown3.Enabled = true;
                bttnDown3to1.Enabled = true;
                pauseThread = false;            
                motor = new Thread(new ThreadStart(runThread));
                motor.Start();

            }
            public void runThread()
            {
                driveLift dlft = new driveLift(replaceTimer);
                pictureBox1.Invoke(dlft);
            }

            public void replaceTimer()
           // private void timer1_Tick(object sender, EventArgs e)
            {
                if (pauseThread == true)
                {
                   motor.Abort();

                }
                else
                {

                    doubleBufferPanel2.Refresh();
                switch (which)
                {
                    case direction.Up:
                        pictureBox1.Top = pictureBox1.Top - 1;
                        myRatioUp = myRatioUp + 1;
                        if (myRatioUp > 2)
                        {
                            myRatioUp = 0;
                            myAngle = myAngle + 1;
                            rotateNeedle();
                        }

                        break;
                    case direction.Down:
                        pictureBox1.Top = pictureBox1.Top + 1;
                        myRatioDown = myRatioDown + 1;
                        if (myRatioDown > 2)
                        {
                            myRatioDown = 0;
                            myAngle = myAngle - 1;
                            rotateNeedle();
                        }
                        break;               
                }
                floorStop();
                Thread.Sleep(liftSpeed);// pause 
                replaceTimer();// repeat
                }
            }


            public void floorStop()
            {
                SoundPlayer simpleSound = new SoundPlayer(Elevator.Properties.Resources.doorbell);
                switch (goingTo)
                {
                    case floor.first:
                        if (pictureBox1.Top > 360)
                        {
                            pauseThread = true;                        
                            pictureBox1.Top = 360;                        
                            simpleSound.Play();

                        }
                        break;                   
                    case floor.second:
                        if (pictureBox1.Top > 175 && pictureBox1.Top < 185)
                        {
                            pauseThread = true;                       
                            pictureBox1.Top = 180;
                            simpleSound.Play();
                        }
                        break;                  
                    case floor.third:
                        if (pictureBox1.Top == 0)
                        {
                            pauseThread = true;                        
                    pictureBox1.Top=0;
                    simpleSound.Play();
                        }
                        break;
                }         

            }

            private void trackBar1_Scroll(object sender, EventArgs e)
            {           
                liftSpeed = (100 - (int)trackBar1.Value);

                label4.Text = ("Lift speed interval = " + liftSpeed.ToString()+ "ms");
            }

            private void doubleBufferPanel1_Paint(object sender, PaintEventArgs e)
            {
                drawFace(e.Graphics);
            }


            public void drawFace(Graphics g)
            {
                g.FillEllipse(Brushes.Black, 5, 5, 90, 90);
                g.FillEllipse(Brushes.Gainsboro, 10, 10, 80, 80);
                g.FillEllipse(Brushes.Black, 30, 30, 40, 40);
                g.DrawString("2", myFont, Brushes.Black, 40, 9);

                g.RotateTransform(-70);
                g.DrawString("1", myFont, Brushes.Black, -39, 22);
                g.RotateTransform(140);
                g.DrawString("3", myFont, Brushes.Black, 55, -70);
                g.ResetTransform();
                g.FillEllipse(Brushes.Red, 40, 40, 20, 20);
            }

            public void rotateNeedle()
            {
                Graphics g = doubleBufferPanel1.CreateGraphics();           
                doubleBufferPanel1.Refresh();
                Matrix mX = new Matrix();
                mX.RotateAt((float)myAngle, new PointF(50, 50));       
                g.Transform = mX;
                g.DrawImage(needle, 48, 10);
            }

            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = doubleBufferPanel1.CreateGraphics();
                drawFace(g);
                rotateNeedle();
            }        


            private void bttnExit_Click(object sender, EventArgs e)
            {
                motor.Abort();          
                this.Close();
            }  



        }
    }

basically this does not have any doors doors to open or close.
things that i dont need:
3 floors
lift speed interval

i need:
2 floors
door that opens and closes
display box that shows which floor the elevator is in.

if its possible add these codes with the application

this.start.Click += new System.EventHandler(this.start_Click);
protected void start_Click(Object o, EventArgs e)
        {


            //Use the CreateGraphics method to create a Graphics object. 
            Graphics formGraphics = this.CreateGraphics();
            // draw frame with a red pen
            System.Drawing.Pen redPen;
            redPen = new System.Drawing.Pen(System.Drawing.Color.Red);
            formGraphics.DrawLine(redPen, 100, 60, 100, 360);
            formGraphics.DrawLine(redPen, 240, 60, 240, 360);
            formGraphics.DrawLine(redPen, 80, 80, 260, 80);
            formGraphics.DrawLine(redPen, 80, 210, 260, 210);
            formGraphics.DrawLine(redPen, 80, 340, 260, 340);
            redPen.Dispose();

            //draw car with a blue brush 
            SolidBrush blueBrush = new SolidBrush(Color.Blue); 
            formGraphics.FillRectangle(blueBrush, 110, 220, 120, 110);
            blueBrush.Dispose();
            formGraphics.Dispose();

            //start button no longer available
            start.Enabled = false;
        }

watch this video, I don't know if it shows any code (I can't get on youtube in work). It should show you how to makes object move in C# and you can adopt that in your code.

I'm sorry but I'm not willing to help you any more, you're year two so you should know how to Google by now and that code is clearly copied.

Advice... Start work earlier, Google more and make friends with the best programmer in your class (they won't do the work for you but you can learn a lot from them).

Here is an old snip I found in my basement that happens to do more or less what you are trying to accomplish. Needs some reworking I guess.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace DumpHeap
{


    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics G = e.Graphics;
            Rectangle R = new Rectangle(10, 10, 100, 200);
            Pen P = new Pen(Color.Blue);
            G.DrawRectangle(P, R);
            Rectangle Door = R;
            Door.Inflate(-1, -1);
            HatchBrush DoorFaceColor = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightPink, Color.LightGray);
            //SolidBrush DoorFaceColor = new SolidBrush(Color.Maroon);
            G.FillRectangle(DoorFaceColor, Door);

            for (int i = 0; i < 99; i++)
            {
                Rectangle Screen = new Rectangle(new Point(11, 11), new Size(i, 199));
                G.FillRectangle(new SolidBrush(this.BackColor), Screen);
                Thread.Sleep(40);
            }
        }
    }
}

hi,can you post me an image on how it looks like.

because i get these 5 errors

Error 1 The name 'InitializeComponent' does not exist in the current context c:\users\rashid\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 17 13 WindowsFormsApplication2

Error 5 The name 'hatchstyle' does not exist in the current context c:\users\rashid\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 28 55 WindowsFormsApplication2

Error 2 'System.EventArgs' does not contain a definition for 'Graphics' and no extension method 'Graphics' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?) c:\users\rashid\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 22 28 WindowsFormsApplication2

Error 4 The type or namespace name 'HatchBrush' could not be found (are you missing a using directive or an assembly reference?) c:\users\rashid\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 28 44 WindowsFormsApplication2

Error 3 The type or namespace name 'HatchBrush' could not be found (are you missing a using directive or an assembly reference?) c:\users\rashid\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 28 13 WindowsFormsApplication2

thanks

Just start a brand new Windows forms application.
Make sure that all these usings are included in your Form1.cs file.

using System
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Threading;

Add a Form Paint event handler via the Properties window.
and fill in the code.
It should work.

sorry as i am a newbie to these programming,

how would i add i add it in the property windows could you guide me step by step

thanks

If you follow the 3 steps in the attachment you will see some code appear in your Form1.cs file. Her you can fill in the code I already gave you. Success.

thanks for for help,i managed to do the project but however
i have couple of other problems

when the doors open or close theres meant to be a yellow thing which is meant to be a light i couldnt do that

and when i press a request buton it has to be highlighted in a yellow colour.

please take a look at this video 0.34 seconds onward :http://www.youtube.com/watch?v=htlX7SxhdHM

thanks

and forgot to mention the doors close atomatically ,how would i make it to open not close until a button is pressed.

thanks

Could not see your video(just a black screen)
Here is my code again, with some explanations, so you can start coming up with some ideas yourself. Also added a button Click handler that you can install, the same way you installed the Paint handler for the form.

private void Form1_Paint(object sender, PaintEventArgs e)
        {
            // just to make e.Graphics from PaintEventArgs shorter
            Graphics G = e.Graphics;

            // create a rectangle with a blue pen
            Rectangle R = new Rectangle(10, 10, 100, 200);
            Pen P = new Pen(Color.Blue);
            G.DrawRectangle(P, R);

            // assign to Door rectangle
            Rectangle Door = R;
            // and shrink by 1 pixel
            Door.Inflate(-1, -1);
            //make a brush
            HatchBrush DoorFaceColor = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightPink, Color.LightGray);
            //SolidBrush DoorFaceColor = new SolidBrush(Color.Maroon);
            // paint the door
            G.FillRectangle(DoorFaceColor, Door);

            // loop with new rectangle over the door rectangle in the backgroundcolor
            // of the form
            for (int i = 0; i < 99; i+=2)
            {
                Rectangle Screen = new Rectangle(new Point(11, 11), new Size(i, 199));
                G.FillRectangle(new SolidBrush(this.BackColor), Screen);
                // slow down
                Thread.Sleep(20);
            }          
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            Button B = sender as Button;
            B.BackColor = Color.Yellow;
        }

hi,thanks for thatddanby .

any ideas why i am recieveing these errors i am nearly finished, thanks

Error 3 The name 'newfloor' does not exist in the current context C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 120 17 Assignment One

Error 5 Cannot implicitly convert type 'string' to 'int' C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 137 28 Assignment One

Error 1 'System.Windows.Forms.Timer' does not contain a definition for 'start' and no extension method 'start' accepting a first argument of type 'System.Windows.Forms.Timer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 101 28 Assignment One

Error 2 'System.Windows.Forms.Timer' does not contain a definition for 'start' and no extension method 'start' accepting a first argument of type 'System.Windows.Forms.Timer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 115 28 Assignment One

Error 4 'System.Windows.Forms.Timer' does not contain a definition for 'start' and no extension method 'start' accepting a first argument of type 'System.Windows.Forms.Timer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 121 24 Assignment One

Error 6 'int' does not contain a definition for 'Tostring' and no extension method 'Tostring' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rashid\Documents\Visual Studio 2010\Projects\Assignment One\Assignment One\Form1.cs 155 36 Assignment One

I think that by copy and pasting each of you errors onto google searchbox you should get pretty good information on what could be going on. It s hard to see what the issue is without any code. Maybe if you copy and paste you lines we could see the problem.

hi,i managed to fix the errors,i feel stupied some were simply capital letters.
but will keep you updated if i need help,
i also need to make an event log that has to record the users e.g. when user presses a button or floors he goes to gets recorded in a database.

is there an simple way of doing this.

thanks

Well onbuttonclick event you should definetly put this into the event

using (SqlConnection con = new SqlConnection(connectionString))
    {
          //connectionString should look like this:Data Source=pc3490ierf43;Initial Catalog=Persons;Integrated Security=True
          //then inside this block call sqlcommand class and sqlreader class
    }

hi, i am trying to use the code:

 private void button1_Click(object sender, System.EventArgs e)
{
Button B = sender as Button;
B.BackColor = Color.Yellow;
}

but the yellow colour should dissaper oern the button aft

i want to click a button,it should be highlighted yellow then when i press another button the colour from the previous button should dissaper and appear on the button that is pressed.

any ideas on how i can do this or change the code

Hi there, if i m correct you want to switch colors between buttons, erase previous color when you click another button, so try this

private void button1_Click(object sender, System.EventArgs e)
{
            Button a = sender as Button;
            a.BackColor = Color.Blue;
            for (int i = 0; i < array.Length; i++) // erasing all button colors but not the one that was clicked
            {
                if (!(sender.Equals(array[i]))) 
                {
                    array[i].BackColor = Color.Silver;
                }
            {
}
        Button[] array; // bare in mind that you have to make an array of buttons
        private void Form1_Load(object sender, EventArgs e)
        {

            button1.Click += thebButtonWasClicked;
            button2.Click += thebButtonWasClicked;
            button3.Click += thebButtonWasClicked;
           array = new Button[3] { button1, button2, button3 };

        }

i suggest that you loop through your form and find buttons on the form and populate those in a array rather than manually store them in the array like i did.

hi, i get these error when i do it

Error   5   The name 'thebButtonWasClicked' does not exist in the current context   C:\Users\Rashid\Pictures\Assignment One\Assignment One\Form1.cs 187 18  Assignment One




Error   1   The name 'array' does not exist in the current context  C:\Users\Rashid\Pictures\Assignment One\Assignment One\Form1.cs 176 33  Assignment One




Error   2   Cannot use local variable 'array' before it is declared C:\Users\Rashid\Pictures\Assignment One\Assignment One\Form1.cs 178 37  Assignment One

and any ideas on how i can create a databse on MS acess
that will show the time and users actions e.g. create a database on microsoft access and import it on visual studio gui to show the states of an elevator.

need to submit the work on 13th dec around 10pm

Well I explained it to you. You have to create a method theButtonWasClicked and you attach it to your event button1.Click,button2.Click,button3.Click. You have to make an array yourself and put you variables button1, button2, button3 into you array manualy or by using a foreach(...) and collect your buttons from your form. Now i realise by looking the second time that i ve made a mistake because i copied your button event and put the code in it, it should be like this

private void thebButtonWasClicked(object sender, System.EventArgs e)
    {
                Button a = sender as Button;
                a.BackColor = Color.Blue;
                for (int i = 0; i < array.Length; i++) // erasing all button colors but not the one that was clicked
                {
                    if (!(sender.Equals(array[i]))) 
                    {
                        array[i].BackColor = Color.Silver;
                    }
                {
    }
            Button[] array; // bare in mind that you have to make an array of buttons
            private void Form1_Load(object sender, EventArgs e)
            {
                button1.Click += thebButtonWasClicked;
                button2.Click += thebButtonWasClicked;
                button3.Click += thebButtonWasClicked;
               array = new Button[3] { button1, button2, button3 };
            }

have a look at this link before doing anything it will help massively. Afer you watch the video, then you should understand what i was talking about.Concerning the database it depends on your knowledge, but if you look at my second previous post you should see how the import should be done. Your deadline is tomorrow i gues so you better hury up. You should have started your project earlier but still good luck, once again see the link Events

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.