I also use a System.Windows.Forms.Timer for this solution, but I don't use the enter/leave mouse events anymore. They have caused me too much grief. Instead I use the MouseMove event on the component I need to know the mouse is over. I have 2 member variables named in this class.
bool Hovering = false;
System.Drawing.Point LastKnownMousePoint = new System.Drawing.Point();
In my case, I wanted to toggle a border around a label. I deal with knowing if the mouse is over the label control I care about as follows:
private void label1_MouseMove(object sender, MouseEventArgs e)
{
// Mouse Position relative to the form... not the control
LastKnownMousePoint = Cursor.Position;
label1.BorderStyle = BorderStyle.Fixed3D;
timer1.Stop();
timer1.Interval = 50; // Very fast (Overkill? :) )
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
System.Drawing.Point point = Cursor.Position;
if (LastKnownMousePoint.Equals(point))
{
// If the mouse is somewhere on the label, I'll call that Hovering.
// Though not technically the MS definition, it works for me.
Hovering = true;
}
else if (Hovering == false)
{
label1.BorderStyle = BorderStyle.None;
timer1.Stop();
}
else
{
Hovering = false;
// Next time the timer ticks, I'll stop the timer and
// Toggle the border.
}
}
This works because I only update the LastKnownMousePoint when the mouse is over the control (a label in this case). So, if the mouse moves outside of the control, I won't update LastKnownMousePoint and I'll know it's time to toggle the border style.