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
Solved

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

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 76
Sending an input value from a view to a controller in MVC 3 22
Add a Condition in ASP Repeater 6 33
abstract class C# 1 30
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 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