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 :)
Printable View
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 :)
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
yeah but it will only change the color when the is on the fourm i want it to change when ever i roll out..
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.
When you roll out, you will be on the form, so it's the same thing.
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
Post 7 is the batter solution of ur problem because it is used by me in my project