Hi all,
I want to display a picture by moving the mouse cursor on a label or picturebox without clicking on them... How can I do that?
PS: The picture would be big sized.
Regards,
wookinhung -VB noobie-
Hi all,
I want to display a picture by moving the mouse cursor on a label or picturebox without clicking on them... How can I do that?
PS: The picture would be big sized.
Regards,
wookinhung -VB noobie-
A simple, reliable VB6 pattern that follows 's "hover" idea and avoids the API "mesh" warned about: create a small borderless preview form containing a PictureBox (set Stretch = True), show it modeless when the mouse moves over the Label or PictureBox, position it at the cursor with GetCursorPos (converted to twips), and use a short Timer to hide the preview when the cursor is no longer over the source control or the preview. This is lightweight, works with large pictures (preload them to avoid pauses), and fixes the "edge" hiding problems.
Example declarations / preload (place in the main form):
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private gPreviewPic As StdPicture ' optional: preload the big image once
' In Form_Load: Set gPreviewPic = LoadPicture("C:\Path\big.jpg") MouseMove on the trigger control (Label or PictureBox):
Private Sub lblHot_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pt As POINTAPI
GetCursorPos pt
With frmPreview
.picPreview.Stretch = True
If Not gPreviewPic Is Nothing Then
.picPreview.Picture = gPreviewPic
Else
.picPreview.Picture = LoadPicture("C:\Path\big.jpg")
End If
.Left = pt.x * Screen.TwipsPerPixelX + 20
.Top = pt.y * Screen.TwipsPerPixelY + 20
.Show vbModeless
End With
tmrPreview.Enabled = True
End Sub Timer check to hide when cursor leaves both areas (set Interval ~150 ms):
Private Sub tmrPreview_Timer()
Dim pt As POINTAPI: GetCursorPos pt
Dim xt As Long, yt As Long
xt = pt.x * Screen.TwipsPerPixelX: yt = pt.y * Screen.TwipsPerPixelY
Dim ctlL As Long, ctlT As Long, ctlR As Long, ctlB As Long
ctlL = Me.Left + lblHot.Left: ctlT = Me.Top + lblHot.Top
ctlR = ctlL + lblHot.Width: ctlB = ctlT + lblHot.Height
Dim pvL As Long, pvT As Long, pvR As Long, pvB As Long
pvL = frmPreview.Left: pvT = frmPreview.Top
pvR = pvL + frmPreview.Width: pvB = pvT + frmPreview.Height
If Not ((xt >= ctlL And xt <= ctlR And yt >= ctlT And yt <= ctlB) _
Or (xt >= pvL And xt <= pvR And yt >= pvT And yt <= pvB)) Then
tmrPreview.Enabled = False
frmPreview.Hide
End If
End Sub Quick tips: set frmPreview.BorderStyle = 0, ShowInTaskbar = False; preload large images into a StdPicture to avoid load lag; adjust offsets and preview size to avoid covering important UI. For absolute pixel-perfect tracking or very odd edge cases, the Windows API (GetWindowRect / TrackMouseEvent) and subclassing give more control but are more complex.
Jump to Post— ddanbe 2,724It is called hover over some object.
Search this site for answers like http://www.daniweb.com/forums/thread133192.html
Jump to Post— Comatose 290Probably is, you've pointed to VB.NET, this is vb 4/5/6
It is called hover over some object.
Search this site for answers like http://www.daniweb.com/forums/thread133192.html
Hi again,
Can I have a simpler example instead? The link doesn't help much because I don't understand it at all...
wookinhung -VB noobie-
Probably is, you've pointed to VB.NET, this is vb 4/5/6
Ooops! This was a slip of the tongue...
Sitting here very sorry and with red cheeks...:$
Hey,
So can anyone help me on this? I'm using VB6 to develop my program but have yet to find any solutions...
wookinhung -VB noobie-
Yeah....
This is the easy way to do it, without the major headaches.... the other way to do is a little less "fluky" that is, sometimes if you are on the edge of the label, it might not always hide or something like that... try it out and see if it suits your needs. The alternative is to use an ugly mesh of API calls.
Hey again,
Oh I see... Thats how they do it... Well, thanks a lot!
+Rep
wookinhung -VB noobie-
Hi again,
Well, that works. Thanks a lot for sharing!
+Rep
wookinhung -VB6 noobie-
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.