【发布时间】:2017-02-24 23:59:42
【问题描述】:
我希望我的图片框左右移动,到目前为止,它们只会向右移动并在到达边缘时消失。代码中有3个敌人,他们都可以向右移动,当他们撞到“墙”时我怎样才能让它们向左移动?玩家可以双向移动。
{
Random _random;
public MainWindow()
{
InitializeComponent();
_random = new Random();
}
private void MainWindow_Load(object sender, EventArgs e)
{
Size s = new System.Drawing.Size(800, 600);
this.ClientSize = s;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
}
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
{
if (e.KeyCode == Keys.Left)
{
Player.Left -= 20;
}
if (e.KeyCode == Keys.Right)
{
Player.Left += 20;
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
int z = _random.Next(0, 10);
int x = _random.Next(0, 20);
int y = _random.Next(0, 30);
LargeEnemy.Left += z;
MediumEnemy.Left += x;
SmallEnemy.Left += y;
}
【问题讨论】:
-
我编辑了我的答案,它适用于图片框
标签: c# winforms visual-studio picturebox