Results 1 to 4 of 4

Thread: MouseMove opposite

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    39

    MouseMove opposite

    Is there any command works in opposite to MouseMove? I want to give a command when my cursor leave the command button.

    Thanks for answering

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MouseMove opposite

    You can use the MosueMove event but there are an X and Y argument that tells you the position of the mouse cursor over it. Just test for when the coordinates are 0 or just about equal the width or height of the button.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: MouseMove opposite

    You could try something like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private bMouseOverButton As Boolean
    4. Private bIgnoreMouseMove As Boolean
    5.  
    6. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.  
    8.     If bIgnoreMouseMove Then
    9.         Exit Sub
    10.     End If
    11.    
    12.     bMouseOverButton = True
    13.    
    14. End Sub
    15.  
    16. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    17.  
    18.     If bIgnoreMouseMove Then
    19.         Exit Sub
    20.     End If
    21.    
    22.     If bMouseOverButton Then
    23.         bIgnoreMouseMove = True
    24.         '
    25.         ' do your button exit stuff
    26.         '
    27.         bMouseOverButton = False
    28.         bIgnoreMouseMove = False
    29.     End If
    30.    
    31. End Sub
    The only problem with this code is if there's not much of your form showing and the user moves the mouse quickly, sometimes the MouseMove event doesn't fire.
    Last edited by pnish; May 9th, 2006 at 02:52 AM. Reason: silly typo
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MouseMove opposite

    VB Code:
    1. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    2. Private Declare Function ReleaseCapture Lib "user32" () As Long
    3. Private Declare Function GetCapture Lib "user32" () As Long
    4.  
    5. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6.     Select Case True
    7.         Case X < 0, Y < 0, X > Command1.Width, Y > Command1.Height
    8.             ' Leaving
    9.             ReleaseCapture
    10.             ' Do Stuff
    11.             Debug.Print "Leaving"
    12.         Case Not GetCapture() = Command1.hwnd
    13.             ' Entering
    14.             SetCapture Command1.hwnd
    15.             ' Do Stuff
    16.             Debug.Print "Entering"
    17.     End Select
    18. End Sub

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