I’m writing a method that wait some seconds and clean the label value. But it can’t be cleaned if the user is with mouse on label.
The code:
public static void CleanIn(this Label label, int miliseconds)
{
Timer timer = new Timer();
timer.Interval = miliseconds;
timer.Tick += (o, e) =>
{
if (!label.Focused)
{
label.ResetText();
timer.Stop();
timer.Dispose();
}
};
timer.Start();
}
The problem is: the value is cleaned independent if the mouse is on label. How to fix this?
The
Focusedproperty relates to whether the user has tabbed to the control, not to whether the mouse is positioned over it. You can use theMousePositionproperty in combination with thePointToClientmethod to determine whether the mouse is over the control, like so: