Results 1 to 8 of 8

Thread: Mouse Over?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    216

    Angry 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

  2. #2
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    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:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Label1.BackColor = vbButtonFace
    3. End Sub
    4.  
    5. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6.     Label1.BackColor = vbRed
    7. End Sub
    Changes are not permanent, but change is. {Neil Peart}

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    216

    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..

  4. #4
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    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}

  5. #5
    Junior Member
    Join Date
    Jun 2006
    Posts
    21

    Re: Mouse Over?

    When you roll out, you will be on the form, so it's the same thing.

  6. #6
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    4. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    5. Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
    6.  
    7. Private Type POINTAPI
    8.         X As Long
    9.         Y As Long
    10. End Type
    11.  
    12. Private Type RECT
    13.         Left As Long
    14.         Top As Long
    15.         Right As Long
    16.         Bottom As Long
    17. End Type
    18.  
    19. Private Sub Form_Load()
    20.   Timer1.Interval = 125 ' This should do
    21.   Frame1.BorderStyle = vbBSNone ' No border for the frame
    22. End Sub
    23.  
    24. Private Sub Timer1_Timer()
    25.   Dim pt As POINTAPI
    26.   Dim fRect As RECT
    27.  
    28.   GetCursorPos pt
    29.   GetWindowRect Frame1.hwnd, fRect
    30.  
    31.   If PtInRect(fRect, pt.X, pt.Y) <> 0 Then
    32.     Frame1.BackColor = vbRed
    33.   Else
    34.     Frame1.BackColor = vbBlue
    35.   End If
    36. End Sub

  7. #7

  8. #8
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    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
  •  



Click Here to Expand Forum to Full Width