on mouse over event

  • 13 years ago

    does anybody know how to code a on mouse over event in VB6

    I have previously tried to use mouse move, but it just does not seem to work the way I want

    I want it to act the same way as the mouseover in HTML/Javscript. When the mouse is over image highlight. ie: swap image. when the mouse is moved from the image, the original image is swapped back.

    If possible, please provide sample code.

  • 13 years ago

    Mousemove surely dosen't quite handle it as well as you would naturally suppose, yet it's one of the simplest ways of simulating  the in HTML/Javscript mouseover in VB.

    I'll explain the theory in pseudocode and post a samplecode form one of my enterprise-grade apps as soon as I get home.

  • 13 years ago


    'Simulating HTML/Javascript type MouseOver Effect in VB
    'VB6 Code by LordRage [Inya-Agha Gabriel]
    'For support email gabey@justice.com

    Option Explicit
    Dim intIndex As Integer
    Dim Mouseover As Boolean

    Private Sub ButtonPicture1_MouseMove(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Test to determine if Mouseover is true, else load picture and set mouseover to true
    'This will prevent the picture box from continually reloading the pictures, thus flickering

    If Mouseover Then
        Exit Sub
       'Load picture based on their tag values
       ButtonPicture1(index).Picture = LoadPicture("Images\" & ButtonPicture1(index).Tag & "1.jpg")
       'Assign the value of index to a variable that will retain the value of index even when this procedure has ended
       intIndex = index
       Mouseover = True
    End If
    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Once the mouse leaves the picture space, wherever its coordinates are captured
    'on the form triggers the swapimage event.
    'However, we test for mouseover to ensure that once the defaultimage has been
    'restored the swapimage event will not be triggered again until it moves over another picture.

    If Mouseover Then
        ButtonPicture1(intIndex).Picture = LoadPicture("Images\" & ButtonPicture1(intIndex).Tag & ".jpg")
        Mouseover = False
    End If
    End Sub

  • 13 years ago

    Use SetCapture() and ReleaseCapture() APIs

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)   

        If X < 0 Or Y < 0 Or X > Picture1.ScaleWidth Or Y > Picture1.ScaleHeight Then

            If Button = 0 Then ReleaseCapture

           ‘ mouse is outside the boundary

    ‘ do your drawing thing here


           ‘ mouse is inside the boudary

            SetCapture Picture1.hwnd

            If Button = vbLeftButton Then

                  ‘ if button is down then         

                  ‘ do your drawing thing here


           ‘ if button is up then

    ‘ do your drawing thing here

            End If

        End If

    End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”