MouseLeave does not work !

  • Thread starter Thread starter arkam
  • Start date Start date
A

arkam

Hi,

I designed a usercontrol and I assigned a handler to the MouseLeave
event !

It fires 80% of the time but when you manage to move your mouse very
fast out of the control it does not !

Does someone know a workaround ?

Arkam
 
arkam said:
Hi,

I designed a usercontrol and I assigned a handler to the MouseLeave
event !

It fires 80% of the time but when you manage to move your mouse very
fast out of the control it does not !

Does someone know a workaround ?

Arkam

You could use a timer tick event instead of mouse leave.
Mouse enter would start the timer and when the mouse leaves the control, the
timer tick event would stop the timer. So the timer only runs when the mouse
is in the control.

It's easier to show a simple example than try to explain. This is for a
normal Form with a panel and a timer dropped on it. // the smaller the timer
interval the faster it works.


//--------------------------------------------------------------------
private void panel1_MouseEnter(object sender, System.EventArgs e)
{
panel1.BackColor = Color.Blue;
timer1.Start();
}
//--------------------------------------------------------------------
private void timer1_Tick(object sender, System.EventArgs e)
{
Point p = new Point(0,0);
p = panel1.PointToScreen(p);

Rectangle r = new Rectangle(p, panel1.ClientSize);

p = Cursor.Position;

if(r.Contains(p) == false)
{
panel1.BackColor = Color.Red;
timer1.Stop();
}
}
//--------------------------------------------------------------------
 
Back
Top