User Control Mouse Hover - Covered by Controls

G

Guest

Hi all,

I'm having some trouble with the Mouse Hover/Leave events on a user
control.

Say I have a user control with a panel covering the whole control. In turn,
a label + picture box cover the panel.

If the mouse is anywhere over the user control, I want the background
colour to change.

I tried handling the user control's mouse hover/leave events but it is not
being picked up. It seems the controls ontop are intercepting the event.

Do I have to loop through all the controls and add a handler? Is that the
best way?

Is there a way to make the User Control intercept the mouse hover/leave
events first before the controls ontop?

Thanks!
 
G

Guest

Hi all,

I'm having some trouble with the Mouse Hover/Leave events on a user
control.

I solved the problem - I implemented IMessageFilter in the User Control:


1. In the constructor you need to register the message filter:

Application.AddMessageFilter(me)

2. Const WM_MOUSEMOVE As Integer = &H200

3.

Public Function PreFilterMessage(ByRef m As
System.Windows.Forms.Message) As Boolean Implements
System.Windows.Forms.IMessageFilter.PreFilterMessage
If m.Msg = WM_MOUSEMOVE Then
If Me.ClientRectangle.Contains(Me.PointToClient
(Control.MousePosition)) Then
Me.BackColor = System.Drawing.SystemColors.Highlight
Else
Me.BackColor = System.Drawing.SystemColors.Control
End If
End If
End Function

This solution is probably the best (?) because there is no flickering
involved.
 
C

Cor Ligthert[MVP]

Hi,

In my idea is it more Net to use the Enter and Leave, the hoover has the
effect that it is all the time firing as long as you hover over the control.

Cor
 
G

Guest

Hi,

In my idea is it more Net to use the Enter and Leave, the hoover has
the effect that it is all the time firing as long as you hover over
the control.


Hi Cor,

I think it runs into the same issue as mouse hover/leave. The top controls
intercept the event preventing a single base event from capturing mouse
movement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top