By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

User Control Mouse Hover - Covered by Controls

P: n/a
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!
Jul 29 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Spam Catcher <sp**********@rogers.comwrote in
news:Xn**********************************@127.0.0. 1:
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.PreFilterMessa ge
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.
Jul 29 '07 #2

P: n/a
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

"Spam Catcher" <sp**********@rogers.comschreef in bericht
news:Xn**********************************@127.0.0. 1...
Spam Catcher <sp**********@rogers.comwrote in
news:Xn**********************************@127.0.0. 1:
>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.PreFilterMessa ge
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.
Jul 29 '07 #3

P: n/a
"Cor Ligthert[MVP]" <no************@planet.nlwrote in
news:FA**********************************@microsof t.com:
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.
Jul 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.