【发布时间】:2017-11-24 15:45:24
【问题描述】:
我想创建一个游戏(多色迷宫),涉及使用箭头键使用图像,但在运行期间,选择的是按钮而不是按下箭头键时的图像?
[更新]
public Form1()
{
InitializeComponent();
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
System.Console.WriteLine("here");
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
// for the image move
int x = Convert.ToInt32(HeartSprite.Location.X);
int y = Convert.ToInt32(HeartSprite.Location.Y);
if (e.KeyCode == Keys.Right) x = x += 25;
else if (e.KeyCode == Keys.Left) x -= 25;
else if (e.KeyCode == Keys.Up) y -= 25;
else if (e.KeyCode == Keys.Down) y += 25;
HeartSprite.Location = new Point(x, y);
e.Handled = true;
}
【问题讨论】:
-
您能详细说明一下吗?方向键有什么移动吗?
-
心形图像预计会通过箭头键移动,但在运行过程中,我只是选择了按钮。