0
我寫了一些wpf代碼,我有一個鼠標,如果光標靜止幾秒鐘,執行一個點擊。我想停止點擊,如果我打開一個新的WPF窗口,我創造了......但似乎dispachers不停止,即使我嘗試幾乎所有的東西......有什麼辦法?不能停止DispacherTimer
public DispatcherTimer NewDispacher = new DispatcherTimer();
public DispatcherTimer NewDispacher2 = new DispatcherTimer();
public void CreateDispachers()
{
NewDispacher.Tick += new EventHandler(NewDispacher_Tick);
NewDispacher.Interval = new TimeSpan(0, 0, 0, 0, 10);
NewDispacher.Start();
NewDispacher2.Tick += new EventHandler(NewDispacher2_Tick);
NewDispacher2.Interval = new TimeSpan(0, 0, 0, 4);
NewDispacher2.Start();
}
public void NewDispacher_Tick(object sender, EventArgs e)
{
pointcur = GetCursorPosition();
}
public void NewDispacher2_Tick(object sender, EventArgs e)
{
pointdiff = GetCursorPosition();
if(form1opened==true)
{
NewDispacher.Stop();
NewDispacher = null;
NewDispacher2.Stop();
NewDispacher2 = null;
}
else if ((pointdiff.X >= pointcur.X - 5)
&& (pointdiff.X <= pointcur.X + 5)
&& (pointdiff.Y >= pointcur.Y - 5)
&& (pointdiff.Y <= pointdiff.Y + 5))
{
DoMouseClick();
pointcur.X = 0;
}
}
我使新的形式打開時,布爾Form1opened =真實的,但即使進入了,如果,dispachers不停止...... 在此先感謝..
設置form1opened = true時使用錯誤引用的可能性很高。你沒有發佈那麼關鍵的代碼,所以無法分辨。 –