473,491 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Mouse hover

37 New Member
Hi
I have a label called buttonLabel. How do i display the label only when the mouse is over the button? I tried using mouse hover event and use a timer. But the label will disappear after 1 sec. But i want the label to disappear only when the mouse is not over the button. Is there a better way to do it?
Aug 18 '07 #1
3 4674
Killer42
8,435 Recognized Expert Expert
Hi
I have a label called buttonLabel. How do i display the label only when the mouse is over the button? I tried using mouse hover event and use a timer. But the label will disappear after 1 sec. But i want the label to disappear only when the mouse is not over the button. Is there a better way to do it?
How about clearing a counter in the button's MouseMove event. Set the timer interval fairly short, have it increment the counter, and hide the button when the counter passes some threshold.

Um... or perhaps you could set a "hey, we've left the button" flag when the mouse moves over the parent form. Or even just set the button's ToolTipText property to the value you want to show.
Aug 21 '07 #2
Sedecrem
4 New Member
I'm not sure if I understand your program but I will try to describe what I am thinking of.

Does the program work as follows:

There is an invisible label that becomes visible when the mouse is over a certain object and then becomes invisible when the mouse moves away.

If so you can do this. Still have your timer, set the interval to 1. Rather than the timer simply turning the visibility off make it first check where the pointer is and relate it to where the object is eg if the pointer is located at x and y then you check whether
x >= the left of the object
x <= the left + the width of the object
y >= the top of the object
y <= the top + the height of the object

If all these are true then the mouse is over the object so let label.Visible = True else if they are not label.Visible = False.

Expand|Select|Wrap|Line Numbers
  1. If x >= cmd1.Left And x <= cmd1.Left + cmd1.Width And y >= cmd1.Top And y <= cmd1.Top + cmd1.Height Then
  2.   lbl1.Visible = True
  3. Else
  4.   lbl1.Visible = False
  5. End If
Another more complicated version is shown here http://www.vb-helper.com/howto_message_over_button.html. They change the message depending on the where the mouse is rather than making a label invisible but its basically he same thing. Also they dynamically determine the controls position which you do not have to do if your form is static.

Sedecrem
Aug 21 '07 #3
Killer42
8,435 Recognized Expert Expert
Thanks for that, Sedecrem. Nice piece of work.

I do have a question and a suggestion:
  • How do you plan to deal with the MouseMove event being captured by other controls?
    Or are you just relying on the label being hidden as the user leaves the control in question, before they hit another one? (Which is more or less what I had in mind with the flag-setting)
    Or did you have another idea in mind (API call, perhaps?) for detecting the mouse position?
  • Just as a general efficiency thing, I'd suggest that in a case like this, any values required to be checked a thousand times a second should be calculated once and placed in a variable. So for instance, the cmd1.Left + cmd1.Width would most likely be calculated in the Form_Load event or a ReSize event, and stored in a form-level variable. Same for the other calculated values. According to doctrine, it would also be worth moving the Left, Top, Width and Height properties into variables, as they are faster to access than control properties.
Aug 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
9459
by: Paul Kaufman | last post by:
What do I add to the style sheet to do this? Thanks. -Paul, the CSS Newbie
7
6497
by: Larry R Harrison Jr | last post by:
I am looking for javascript and a basic tutorial on how to make mouse-over drop-down menus--the type that when you "hover" over a subject links relevant to that subject "emerge" which you can then...
4
2224
by: Raj Chudasama | last post by:
I have a controls similiar to the windows calculator. (Please press some buttons on your calculator to see what i am talking about) So when u hover over a button it will change the state (it...
3
2052
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
0
1439
by: StriderBob | last post by:
In a simple two form project, use a button on each form to Show() the other form and Hide() the current form. Add MouseEnter and MouseLeave events to both buttons so they change the image on each...
3
4284
by: Spam Catcher | last post by:
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...
2
5782
by: sundarvenkata | last post by:
Hi All, Can somebody tell me if there is an event to indicate mouse hover over a control in wxPython? EVT_MOTION does not seem to cut it. Thanks in advance, Sundar
5
8043
by: kimiraikkonen | last post by:
Hi, I couldn't find a necessary class which shows when mouse hovers on a link in Webbrowser control. Think of there's a status bar(text), when mouse comes on a link, the URL must be shown in...
2
4657
by: bahnfire | last post by:
Hi, I am hoping that I finally have the right group :-) I am using Visual C++ Express 2008 and am trying to change the taskbar icon that I am using (notifyIcon1) as some state changes (button...
0
7115
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
6978
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
7154
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
7190
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...
1
6858
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...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.