Results 1 to 10 of 10

Thread: mouse move question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Australia
    Posts
    115

    mouse move question

    I have created a label on a form, to imitate a hyperlink on browser, such that when it detects mouse movement over the label, it changes color and changed back to the original color when mouse moves out of the control, and opens the browser upon left click.

    I have no problem detecting mouse movement when it's over the label. But how do I detect the mouse has left the label? Is it possible not to use API?

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    to do that, one uses the SetCapture and ReleaseCapture API calls (that i know of).
    The problem is that the SetCapture call requires a hWnd, which the label doesn't have. if u can think of some other control that does have a hWnd then:

    VB Code:
    1. Static CtrMov As Boolean
    2.  
    3.     With objControl
    4.       If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
    5.         'lost mouse focus
    6.         ReleaseCapture
    7.         CtrMov = False
    8.       Else
    9.         SetCapture .hWnd
    10.         If CtrMov = False Then
    11.           'gained mouse focus
    12.           CtrMov = True
    13.         End If
    14.       End If
    15.     End With

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    forgot to give the declarations. here they are:

    VB Code:
    1. Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
    2.  
    3. Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Australia
    Posts
    115
    I guess I can use a borderless textbox. Thank you for your help. I'll give it a try.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Give this ago, you will need to adapt it.

    It demonstrates the Mouse over 1 of 2 buttons.
    (ulimately for a Button Menu selection)

    Bruce.
    ________
    JulyaChannel
    Attached Files Attached Files
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:59 AM.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This should do it.
    When u pass the mouse over, the lable will change colour.
    When it leaves the Label it will change back.

    Use the Arrow.ico I provided in the zip.
    VB Code:
    1. Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    2.     If State = vbLeave Then
    3.         Label1.Drag vbEndDrag
    4.         Label1.BackColor = &H8000000F
    5.     End If
    6. End Sub
    7.  
    8. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.     Label1.Drag vbBeginDrag
    10.     Label1.DragIcon = LoadPicture(App.Path & "\Arrowbj.ico")
    11.     Label1.BackColor = &HFF&
    12. End Sub
    And, this will change the text:
    VB Code:
    1. Private Sub Label1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    2.     If State = vbLeave Then
    3.         Label1.Drag vbEndDrag
    4.         Label1.ForeColor = &H0&
    5.     End If
    6. End Sub
    7.  
    8. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.     Label1.Drag vbBeginDrag
    10.     Label1.DragIcon = LoadPicture(App.Path & "\Arrowbj.ico")
    11.     Label1.ForeColor = &HFF00&
    12. End Sub
    Last edited by Bruce Fox; Mar 7th, 2002 at 01:36 AM.

  7. #7
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Hmmmm??!!

    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.FontBold = True
    End Sub


    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Label1.FontBold = False


    End Sub

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    That works Libro,
    However, you 'fire' the Form MouseMove continually when moving around

    Hence, what I provided eliminates that.
    ________
    Vapir no2 vaporizer
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:59 AM.

  9. #9
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Im aware of that. I use this in many apps i made. And i dont see any difference for me anyway.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Australia
    Posts
    115
    The Drag-Drop method doesn't work because it doesn't capture the mouse button event, which I need to fire up some application upon clicking of a mouse button.

    So I had to use the ReleaseCapture and SetCapture APIs. I used Picutre Box control to display the text. The result is exactly how I wanted. FYI, the TextBox control didn't work as well since a cursor is set in the control when mouse is clicked or got the focus.

    Thank you all for your suggestions.

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