C#鼠标移动事件,时间循环停止

问题描述:

我已经创建了一个游戏,你需要拍摄一个每0.5秒在屏幕上随机移动的鼹鼠。C#鼠标移动事件,时间循环停止

当我将鼠标移动到屏幕上而不停止时,时间循环似乎冻结,直到鼠标停止移动。

我有一个鼠标移动事件,刷新屏幕, 和一个时间循环事件,每0.5秒更新一次窗体。我怎样才能让这两个事件在不干扰彼此的情况下运行?

+3

你可以分享你的代码呢? – Prajwal

我不能正确理解你,而是由你给的线索,我可以通过使一个方法的线程进程会做trick.since建议ü了你改变,你必须使用BeginInvoke方法的UIElement。

   public delegate void InvokeDelegate(); 

       private void Invoke_Click(object sender, EventArgs e) 
        { 
         mole.BeginInvoke(new InvokeDelegate(InvokeMethod)); 
        } 
         public void InvokeMethod() 
        { 
         // change your mole position here 
         } 

您可以使用Backgroundworker。订阅Backgroundworker的DoWork活动。你可以计数你的计时器或观看该事件。

You can look here