Solved

MouseIsNearby Function Only Evaluates When Mouse Pointer is Hovering Directly Over LineShape

Posted on 2013-05-21
2
336 Views
Last Modified: 2013-05-21
I am using a mouseisnearby function to control a nearby lineshape's color and endpoint cursor style, based on proximity to a nearby lineshape.   Something I noticed was that my mouseisnearby function only evaluates when the mouse pointer hovers directly over the line, and not when the mouse pointer is in clear space on the form, but close to the lineshape's endpoint.  The absolute value of the delta for X and Y is used in mouseisnearby, but how can I implement the mouseisnearby function when not hovering directly over the line?    


  Public Sub ShapeContainerMouseMoveEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        For Each ls As LineShape In Me.SC.Shapes 'Lines
            If MouseIsNearBy(ls.EndPoint) = True Then
                SelectedLS = ls
                SelectedLS.BorderColor = Color.Red
                Me.Refresh()
                NearLineEndPoint = True
                ls.Cursor = Cursors.Hand
            End If
            If MouseIsNearBy(ls.EndPoint) = False Then
                ls.BorderColor = Color.Black
                Me.Refresh()
                 NearLineEndPoint = False
                ls.Cursor = Cursors.Default
            End If
        Next
 End Sub

 Private Function MouseIsNearBy(ByVal testPoint As Point) As Boolean
        testPoint = Me.PointToScreen(testPoint)
        Return Math.Abs(testPoint.X - MousePosition.X) <= HitTestDelta AndAlso Math.Abs(testPoint.Y - MousePosition.Y) <= HitTestDelta
    End Function

Open in new window

0
Comment
Question by:lep1
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39186231
Try handling the Forms MouseMove() event and calling your existing handler:
    Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        ShapeContainerMouseMoveEventHandler(Nothing, e)
    End Sub

    Public Sub ShapeContainerMouseMoveEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        ...
    End Sub

Open in new window

0
 

Author Comment

by:lep1
ID: 39186433
I actually moved the mouseisnearby function evaluation, which loops thru all LS to see if cursor.X,Y are near the LS endpoint (to change LS color and current cursor style), directly into the form1 mouse move event.  I noticed that I have an addhandler for the LS's which point to shapecontainermousemove, down, up, etc.  It seems that you might be able to use the form mousemove, down, up instead of the shape mouse move, down, up to detect closeness to an LS endpoint, then mouse down and move (drag) the endpoint, but again, when I moved the corresponding code in the shape move , down, up routines into the form move, down, up, I couldn't move the LS endpoint after downing near the endpoint -- at least when the mouse was close enough to trigger mouseisnearby.  The LS could only moved if I clicked down when precisely over the LS near the endpoint.  I'll see what your suggestion does and then comment. Thx
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now