im Trying to make a label move when i push The WASD Keys But as i push it pauses i dont know how to fix it so it goes as soon as i push it Heres Code So Far

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 Practice_steerc
{
    public partial class Form1 : Form
    {
        int Xaxis = 5;
        int Yaxis = 5;

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.W)
            {
                Yaxis = -5;
            }
            else if (e.KeyCode == Keys.D)
            {
                Xaxis = +5;
            }
            else if (e.KeyCode == Keys.S)
            {
                Yaxis = +5;
            }
            else if (e.KeyCode == Keys.A)
            {
                Xaxis = -5;
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {

        }
    }
}

did you8 set the location property of your label to the new Points using your Xaxis and Yaxis ?

tried refreshing the label?

label1.refresh();
or
label1.invalidate();

fairly sure they both repaint the control..
also try setting double buffer on the control...

that could help you..


also try a "while" loop instead of "if"
by logic, using while, will mean, while you press W, do this and continue..
instead of, if W, do this. check again...

int Xaxis = 5;
int Yaxis = 5;
if (e.KeyCode == Keys.W)
{
LabelName.Location = new Point(Xaxis,-5);
}
else if (e.KeyCode == Keys.D)
{
LabelName.Location = new Point(5,Yaxis);
}
else if (e.KeyCode == Keys.S)
{
LabelName.Location = new Point(Xaxis,5);
}
else if (e.KeyCode == Keys.A)
{
LabelName.Location = new Point(-5,Yaxis);
}
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.