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

Re: MouseLeave does not work ! by Martin

Martin
Fri Jan 09 16:52:38 CST 2004


"arkam" <arkam@caramail.com> wrote in message
news:e185dcd1.0401051332.73a04931@posting.google.com...
> 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();
}
}
//--------------------------------------------------------------------