|
-
Jun 30th, 2006, 05:30 PM
#1
Thread Starter
Addicted Member
Mouse Over?
How can out mouse over and mouse out event on a label for example i want a label's backcolor to change to red when the mouse is over it and when i take my mouse off the label its changes to blue help plz
-
Jun 30th, 2006, 05:53 PM
#2
Addicted Member
Re: Mouse Over?
I don't know of any mouse out. I think the only way you can determine when the mouse has moved off the label is by determining when it's moving over another control.
In this example I change the label to red when the mouse is over the label then I change it back to the original color when the mouse moves over the form.
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbButtonFace
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbRed
End Sub
Changes are not permanent, but change is. {Neil Peart}
-
Jun 30th, 2006, 05:55 PM
#3
Thread Starter
Addicted Member
Re: Mouse Over?
yeah but it will only change the color when the is on the fourm i want it to change when ever i roll out..
-
Jun 30th, 2006, 06:00 PM
#4
Addicted Member
Re: Mouse Over?
A more complicated method is to monitor the x,y coordinates of the mouse. You would also have to define the area that your label coveres. If the mouse coord's are not within the area of your label then you would change the color back.
Someone might have already made some code to make this all really easy. Without some 3rd party code, I don't think it will be easy.
Changes are not permanent, but change is. {Neil Peart}
-
Jun 30th, 2006, 06:32 PM
#5
Junior Member
Re: Mouse Over?
When you roll out, you will be on the form, so it's the same thing.
-
Jun 30th, 2006, 10:15 PM
#6
Re: Mouse Over?
When the mouse moves off of the label, it is not necessarily on the form. It could be on an adjacent or nearby control, or the label could be in a picturebox or frame.
Here is a simple solution using a Frame control as a container for the label. Paste this code in a form with a frame (Frame1) and a timer (Timer1).
VB Code:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Timer1.Interval = 125 ' This should do
Frame1.BorderStyle = vbBSNone ' No border for the frame
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim fRect As RECT
GetCursorPos pt
GetWindowRect Frame1.hwnd, fRect
If PtInRect(fRect, pt.X, pt.Y) <> 0 Then
Frame1.BackColor = vbRed
Else
Frame1.BackColor = vbBlue
End If
End Sub
-
Jul 1st, 2006, 05:24 AM
#7
-
Jul 1st, 2006, 05:32 AM
#8
Re: Mouse Over?
Post 7 is the batter solution of ur problem because it is used by me in my project
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|