473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

User Control Mouse Hover - Covered by Controls

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
3 4276
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: A G Benny | last post by:
Hi, I have a numericupdown control in my form. I added a tool tip control and set the numericupdown control's property to show the tool tip text. But when i hover over the control, no tool tip...
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
0
by: Dirk Fust | last post by:
Hi! I'm writing a little application, where I want to be noticed, when the mouse leaves my window. Because the window has no border, is non-rectangular (drawn vie GDI+) and nearly completly...
3
by: AinO | last post by:
Hi, (VS2003/c# - System.Windows.Forms) Is there a way to know (have an event triggered) if the mouse leaves a form, if this form's client area is completly covered with child controls ? I...
4
by: Vidae - Recursos Humanos | last post by:
Hello all. Is there any way to do a kind of "a.hover" in an ASP.NET 2.0 LinkButton control? I mean, I need my LinkButton changes its color when the mouse hovers the control. Thank you very...
6
by: Rob | last post by:
This is a curious problem. It seems like it should be quite easy. Of course a timer is used to determine when form should be closed, but how do you consistently reset the timer when the mouse is...
9
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in...
1
by: johnson.bj | last post by:
I have a relatively minor problem that has been bugging me for a long time. I have created a user control which consists of a few panels and labels. What I want to do with this user control is to...
1
by: RobcPettit | last post by:
Hi Ive added a usercontrol to a form. When I hover over the control with the mouse, it shows the timer icon, but my control is just a layout and Im not actively updateting it. If I come of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.