2 u014442978 u014442978 于 2014.10.05 17:44 提问

C# 编译没有错,但运行不对

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();
    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!