Sooo im doin this project for school and im super stuck on the keydown command, i dont know how to get it to work at all! my teacher is also has learned c# but forgot alot of it.

so basically i want it so that if i press the up arrow the car moves up. i have also googled the s*** out of it and none of it makes sense to me... PLEASE HELP!!!

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
    {
        int carX = 230;
        int carY = 230;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
            private void carMovement_Tick(object sender, EventArgs e)
        {

            if (KeyDown += Keys.Up)
            {
                carY--;

                this.carImage.Location = new Point(carX, carY);
                if (carY == 0)
                {
                    carY = 0;
                }
            }

        }

    }
}

Try this code:

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
    {
        int carX = 230;
        int carY = 230;

        public Form1()
        {
            InitializeComponent();

            this.KeyDown += new KeyEventHandler(Form1_KeyDown);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

       void Form1_KeyDown(object sender, KeyEventArgs e)
        {
              if(e.KeyCode == Keys.Up)
              {
                    carY--;

                    this.carImage.Location = new Point(carX, carY);
              }
        }

    }
}

Thanks

awesome thanks!!!

one more question to set me off in the right direction...

i want the picturebox to rotate to simulate the car turning, but even if i figure out how to get it to rotate say 32 degrees to the left, how do i make the car move in that direction?

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.