mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-08-20 20:41:56 +12:00
39 lines
1,019 B
C#
39 lines
1,019 B
C#
using System;
|
|
using Timer = System.Windows.Forms.Timer;
|
|
|
|
namespace SystemTrayMenu.Helper
|
|
{
|
|
class WaitFastLeave : IDisposable
|
|
{
|
|
public event EventHandler Leave;
|
|
|
|
Timer timerSecondLeaveCheck = new Timer();
|
|
|
|
public WaitFastLeave()
|
|
{
|
|
timerSecondLeaveCheck.Interval = 200;
|
|
timerSecondLeaveCheck.Tick += LeaveWorkaround_Tick;
|
|
}
|
|
|
|
// When menu not activated and mouse leaves menu very fast,
|
|
// mouse still on menu but we not get leave event again
|
|
// as workaround we call the check again (200ms later)
|
|
public void Start()
|
|
{
|
|
Leave.Invoke();
|
|
timerSecondLeaveCheck.Stop();
|
|
timerSecondLeaveCheck.Start();
|
|
}
|
|
|
|
private void LeaveWorkaround_Tick(object sender, EventArgs e)
|
|
{
|
|
timerSecondLeaveCheck.Stop();
|
|
Leave.Invoke();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
timerSecondLeaveCheck.Dispose();
|
|
}
|
|
}
|
|
}
|