Results 1 to 5 of 5

Thread: MouseHover same as MouseMove? How to get the x/y position of the window?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2025
    Posts
    182

    MouseHover same as MouseMove? How to get the x/y position of the window?

    In VBA code the x/y parameters are sent with the call, so it's easy to do what I want with the item. (see below) I don't get a mousemove option from the tool, nor do I get x/y from e.

    How would I get the x/y position of the mouse to determine if the cursor is on the object or not? I use the move over the object as a sign to extend the object for viewing hidden items in the GroupBox. Will the MouseHover do the same thing for me?

    Code:
    Private Sub FRM_REVIEW_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        
        If (CurrentPhase = eRUN_MAIN_SECTION) Then
            FRM_INVESTIGATION_CONCLUSION.ZOrder (1)
            FRM_RISK.ZOrder (1)
            FRM_CAPA.ZOrder (1)
    '        If (FRM_DHR.Height = 18) Then
                FRM_REVIEW.ZOrder (0)
    '        End If
    
            FRM_REVIEW.SetFocus
    
            DoEvents
            If (X > 5 And X < 888 And Y < 320 And Y > -1) Then ' And FRM_REVIEW.Height < 338) Then
                FRM_RISK.Height = 18
                FRM_CAPA.Height = 18
                FRM_DHR.Height = 18
                FRM_REVIEW.Height = 336
            Else
                FRM_CAPA.Height = 18
                FRM_DHR.Height = 18
                FRM_RISK.Height = 18
                FRM_REVIEW.Height = 18
            End If
            DoEvents
        End If
        
    End Sub
    Thanks for the support.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,070

    Re: MouseHover same as MouseMove? How to get the x/y position of the window?

    Code:
    Private Sub Form1_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
        Dim mousePosition = PointToClient(Cursor.Position)
    
        '...
    End Sub
    
    Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
        Dim mousePosition = e.Location
    
        '...
    End Sub
    The Cursor.Position property is in screen coordinates, so you can use the PointToClient method of the form to convert that to client coordinates, i.e. relative to the top-left corner of the form. All controls (forms are controls too) have PointToClient and PointToScreen methods to convert between client and screen coordinates in both directions. These are often used in tandem to convert a Point relative to one control to a Point relative to another, e.g. a mouse click on a child control can be converted to form coordinates by converting from the child client coordinates to screen coordinates first, then from screen to form client.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,368

    Re: MouseHover same as MouseMove? How to get the x/y position of the window?

    Do you really need to capture the x/y coordinates? The GroupBox control has a MouseHover event. You can use that to redimension the GroupBox

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2025
    Posts
    182

    Re: MouseHover same as MouseMove? How to get the x/y position of the window?

    Quote Originally Posted by wes4dbt View Post
    Do you really need to capture the x/y coordinates? The GroupBox control has a MouseHover event. You can use that to redimension the GroupBox
    How do I know when the mouse has moved "IN" and "OUT" of the window? To me hover will only be called 1 time, but I may be wrong. I need continuous calls to check if the mouse has moved out of the window to resize it.

    Does Hover allow this? Or is it a 1 time call as I suspect?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,070

    Re: MouseHover same as MouseMove? How to get the x/y position of the window?

    Do you actually understand what MouseHover means? It is not an indication that the mouse pointer is over the control. It is specifically an indication that the mouse pointer is over the control and is not moving. Is that specifically what you want? If you want to know when the mouse pointer enters and leaves the bounds of a control then the MouseEnter and MouseLeave events are what you want. That said, they are complicated by the fact that a container control will raise the MouseLeave event when the mouse pointer enters a child control, so you may need to use a bit of logic for containers like Panels and GroupBoxes if you consider the mouse pointer to still be within the container when it is specifically within a child of that container.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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