SystemTrayMenu/Helper/WaitFastLeave.cs
2019-07-04 19:04:14 +02:00

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