Results 1 to 3 of 3

Thread: Mouse over and mouse out

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Malaysia
    Posts
    69
    Is there an event in VB that similar to HTML mouseover and mouseout?

    I couldn't find it and the best alternative I could find is mousemove. But mousemove event trigger even I move my mouse around the current object which result in the code under that event run and run again.

    And I couldn't find mouseout event.

    Thx

  2. #2

    Nope

    Sorry there isn't. You have to fake it in some way. On alternative is on the mousemove event of the objects parent, you would put the code that you would normally put in the MouseOut. Realize thought that you might have to put that code on other objects too, depending on how close other objects are to the current object.
    Senior Systems Architect/Programmer

  3. #3
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    This is a copy of code that emulates the MouseOver and
    MouseOut events. I downloaded it quite a while ago. The
    origin of the code is from a guy named seaweed. Copy this
    code into a form with a Timer control, a Label control, and
    a Command button control (leave the names at the default
    Timer1, Label1, and Command1). When you run it, move your
    mouse over the label and command button for an example of
    the Emulated MouseOver and MouseOut events. It works
    pretty well.

    Hope this helps.


    Code:
    Option Explicit
    
    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 Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    'There is probably a better way to implement the addition of the height
    'of the title bar. If you find a way, please send me an email describing
    'your method. My email is:  [email protected]
    Private Const TitleBarHeight As Integer = 350
    
    Private Sub Form_Load()
        Timer1.Interval = 200
        Label1.Caption = "Hyperlink"
        Command1.Caption = "MouseNotOver"
    End Sub
    
    Private Function MouseOver(ControlIn As Control) As Boolean
        Dim ControlRect As RECT, CursorPos As POINTAPI
            
        GetCursorPos CursorPos
        
        ControlRect.Left = (Me.Left + ControlIn.Left) / Screen.TwipsPerPixelX
        ControlRect.Top = (Me.Top + ControlIn.Top + TitleBarHeight) / Screen.TwipsPerPixelY
        ControlRect.Right = (Me.Left + ControlIn.Left + ControlIn.Width) / Screen.TwipsPerPixelX
        ControlRect.Bottom = (Me.Top + ControlIn.Top + TitleBarHeight + ControlIn.Height) / Screen.TwipsPerPixelY
        
        If CursorPos.X > ControlRect.Left And _
            CursorPos.X < ControlRect.Right And _
            CursorPos.Y > ControlRect.Top And _
            CursorPos.Y < ControlRect.Bottom Then
                MouseOver = True
        Else
            MouseOver = False
        End If
    
    End Function
    
    Private Sub Timer1_Timer()
        
        If MouseOver(Command1) Then
            Command1.Caption = "MouseOver"
        Else
            Command1.Caption = "MouseNotOver"
        End If
        
        If MouseOver(Label1) Then
            Label1.FontUnderline = True
            Label1.ForeColor = vbBlue
        Else
            Label1.FontUnderline = False
            Label1.ForeColor = vbButtonText
        End If
    End Sub
    JC

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