Solved

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

Posted on 2013-05-21
2
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

696 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