So, I am kinda stucked on my moving PICTURE box; at the moment my form 2 loads the picture box starts moving, that is exactly what I wanted, However it isn't in my Control and that's what I am trying to do, but I've failed.....All I want is the direction of the moving picture Box to be controlled by the keys......Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
timer1.Start();
}
private void Form2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
pictureBox1.Location = new Point(pictureBox1.Location.X + 5, pictureBox1.Location.Y);
}
if (e.KeyCode == Keys.Up)
{
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 5);
}
if (e.KeyCode == Keys.Left)
{
pictureBox1.Location = new Point(pictureBox1.Location.X - 5, pictureBox1.Location.Y);
}
if (e.KeyCode == Keys.Down)
{
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 5);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Location = new Point(pictureBox1.Location.X + 25, pictureBox1.Location.Y);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
See Question&Answers more detail:os