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;
using System.Threading;
namespace _111
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int xold, yold;
string direction ="Right";
public void MoveHead()
{
while (true)
{
xold = this.lblHead.Left;
yold = this.lblHead.Top;
switch (direction)
{
case "Up":
this.lblHead.Top -= 15;
if (this.lblHead.Top <= 0)
{
this.lblHead.Top = 585;
}
break;
case "Down":
this.lblHead.Top += 15;
if (this.lblHead.Top >= 585)
{
this.lblHead.Top = 0;
}
break;
case "Right":
this.lblHead.Top += 15;
if (this.lblHead.Left >= 585)
{
this.lblHead.Left = 0;
}
break;
case "Left":
this.lblHead.Top -= 15;
if (this.lblHead.Left <= 0)
{
this.lblHead.Left = 585;
}
break;
}
Thread.Sleep(100);
}
}
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
Thread thread = new Thread(new ThreadStart(MoveHead));
thread.Start();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
direction = e.KeyCode.ToString();
}
}
}