Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-05-21
2
Medium Priority
?
354 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 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