Witam. Mógł by mi ktoś powiedzieć gdzie jest błąd i dlaczego button nie zmienia swojego położenia po naciśnięciu danego klawisza?
oto kod:
public class Program
{
static void Main()
{
MyForm t = new MyForm();
Application.Run(t);
}
}
public class MyForm : Form
{
private Button but;
public MyForm()
{
but = new Button();
but.Location = new System.Drawing.Point(10, 10);
this.Controls.Add(but);
this.KeyDown += new KeyEventHandler(this.t_KeyDown);
}
public void t_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Left:
but.Location = new System.Drawing.Point(but.Location.X - 1, but.Location.Y);
break;
case Keys.Right:
but.Location = new System.Drawing.Point(but.Location.X + 1, but.Location.Y);
break;
case Keys.Up:
but.Location = new System.Drawing.Point(but.Location.X, but.Location.Y + 1);
break;
case Keys.Down:
but.Location = new System.Drawing.Point(but.Location.X, but.Location.Y - 1);
break;
default:
break;
}
}
aplikacja w ogóle nie reaguje na naciśnięte klawisze ;/
}