我正在尝试使由主击键表示的表单向左或向右移动由辅助击键表示的多个像素,但到目前为止我还没有做任何事情。据我所知,我在这里应该没有问题。我也将 KeyPreview 设置为 true。
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
this.Close();
int movement = 0;
if (e.KeyCode == Keys.R)
lastEntered = 'r';
else if (e.KeyCode == Keys.L)
lastEntered = 'l';
else
{
if (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)
{
movement = (int)(e.KeyCode - Keys.NumPad0);
Console.WriteLine(movement);
this.Left += movement;
}
if (lastEntered == 'r')
this.Left += movement;
else if (lastEntered == 'l')
this.Left -= movement;
}
}