Solved

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

Posted on 2013-05-21
2
333 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

19 Experts available now in Live!

Get 1:1 Help Now