• Log in or sign up for an account here: https://www.sythe.org/login

Vb Question...

Visual Basic Matt

Apprentice
Joined
Jan 29, 2008
Sythe Gold
56
Messages
647
Location
Evurar
Vb Question...
I'm trying to make it so that when you hover over an image another image will move to your mouse position, so that its like an icon. (I don't want it to just make the image the icon as load it from the properties message.) I want to use the image I have captions and text boxes on. So, when you hover over an object it will show the thing to edit it and it will move along with your mouse. Sorry if i didn't explain that very well, I tryied to make it as easy to understand as possible... =|
 
Vb Question...
Do you want to replace the cursor, or place an image under it?
 
Vb Question...
Copy and paste this into your form, be sure to have the picture you want to hover over called Picture1 and the picture you want to appear when you hover over Picture1 called Picture2.
Also this will only work with Picture Boxes NOT Image Boxes.

Code:
Option Explicit

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As Rect) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) 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()
    Me.ScaleMode = 3
End Sub

Private Sub tmrMouseOver_Timer()
    Dim blnMouseOver As Boolean
    Dim MousePos As PointAPI
    Dim wRect As Rect
    blnMouseOver = IsMouseOver(Picture1.hWnd)
    If blnMouseOver = True Then
        GetCursorPos MousePos
        GetWindowRect Me.hWnd, wRect
        Picture2.Left = (MousePos.X - wRect.Left)
        Picture2.Top = (MousePos.Y - wRect.Top)
        Picture2.Visible = True
    Else
        Picture2.Visible = False
    End If
End Sub

Private Function IsMouseOver(hWnd As Long) As Boolean
    Dim wRect As Rect
    Dim MousePos As PointAPI
    GetCursorPos MousePos
    GetWindowRect hWnd, wRect
    IsMouseOver = IIf((MousePos.X <= wRect.Right And MousePos.X >= wRect.Left) And (MousePos.Y <= wRect.Bottom And MousePos.Y >= wRect.Top), True, False)
End Function

I've also attached the project.
 

Attachments

Vb Question...
Nice covey :)

Hope it all works for you
 
Runescape Gamblingrunescape gambling
Back
Top