0

C# windows picture box movement

Alright I’m trying to make a picture box named player move in C# windows and I want to know why it doesn’t work using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace testmarioform { public partial class Form1 : Form { bool right; bool left; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { if (right == true) { Player.Left += 5; } if (left == true) { Player.Left -= 5; } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { right = true; } if (e.KeyCode == Keys.Left) { left = true; } } private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { right = false; } if (e.KeyCode == Keys.Left) { left = false; } } } }

21st Feb 2020, 12:53 AM
Hasan Alharaz
Hasan Alharaz - avatar
1 Answer
+ 2
setInterval in Form1_KeyDown to call timer1_Tick
21st Feb 2020, 12:57 AM
Gordon
Gordon - avatar