MouseHover / MouseLeave event in the whole window

I have a subclass of Form with handlers for MouseHover and MouseLeave . When the pointer is in the background of the window, the events work fine, but when the pointer moves to the control inside , it raises the MouseLeave event.

In any case, there is an event covering the entire window.

(.NET 2.0, Visual Studio 2005, Windows XP.)

+7
c # events winforms mouseleave mousehover
source share
4 answers

When a mouse stop event is triggered, one option is to check the current position of the pointer and see if it is in the form area. I'm not sure if the best option is available.

Edit: We have a similar question that might interest you. How to determine if a mouse is inside the entire form and child controls in C #?

+6
source share

Ovveride MouseLeave event does not fire while mouse enters child control

  protected override void OnMouseLeave(EventArgs e) { if (this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition))) return; else { base.OnMouseLeave(e); } } 
+8
source share

It is not possible to make MouseLeave reliable for container management. Pull this problem with a timer:

 public partial class Form1 : Form { public Form1() { InitializeComponent(); timer1.Interval = 200; timer1.Tick += new EventHandler(timer1_Tick); timer1.Enabled = true; } private bool mEntered; void timer1_Tick(object sender, EventArgs e) { Point pos = this.PointToClient(Cursor.Position); bool entered = this.ClientRectangle.Contains(pos); if (entered != mEntered) { mEntered = entered; if (!entered) { // Do your leave stuff //... } } } } 
+5
source share

In your user control, create a mousehover event for your control similar to this (or another type of event), e.g.

 private void picBoxThumb_MouseHover(object sender, EventArgs e) { // Call Parent OnMouseHover Event OnMouseHover(EventArgs.Empty); } 

Your WinForm hosting the UserControl has this for UserControl to handle MouseOver, so put this in your Designer.cs

 this.thumbImage1.MouseHover += new System.EventHandler(this.ThumbnailMouseHover); 

What calls this method on your WinForm

 private void ThumbnailMouseHover(object sender, EventArgs e) { ThumbImage thumb = (ThumbImage) sender; } 

Where ThumbImage is a usercontrol type

0
source share

All Articles