Last active
October 30, 2015 00:03
-
-
Save raimckenzie/458f8e2ffae67f92e50e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CentSharp | |
{ | |
public partial class Form1 : Form | |
{ | |
int step = 6; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
//On Form load (Application Start) | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
//Register event listeners. | |
Form form1 = this; | |
form1.KeyDown += new KeyEventHandler(Form1_KeyDown); | |
} | |
//KeyDown event. | |
private void Form1_KeyDown(object sender, KeyEventArgs e) | |
{ | |
switch (e.KeyCode) | |
{ | |
case Keys.Up: //If UP key is pressed. | |
//Move picture box to new location. | |
octo.Location = new Point(octo.Location.X, octo.Location.Y - step); | |
break; | |
case Keys.Down: //If DOWN key is pressed. | |
//Move picture box to new location. | |
octo.Location = new Point(octo.Location.X, octo.Location.Y + step); | |
break; | |
case Keys.Left: //If LEFT key is pressed. | |
//Move picture box to new location. | |
octo.Location = new Point(octo.Location.X - step, octo.Location.Y); | |
break; | |
case Keys.Right: //If RIGHT key is pressed. | |
//Move picture box to new location. | |
octo.Location = new Point(octo.Location.X + step, octo.Location.Y); | |
break; | |
case Keys.Space: //If SPACE key is pressed. | |
octo.Location = new Point(300, 300); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment