Link to home
Start Free TrialLog in
Avatar of lep1
lep1

asked on

Undetectable offset between LineShape true location and visual location

The code below is used to test whether the mouse pointer is near the endpoints of  LineShape control.  If true, upon mouse down, the selected end of the LineShape is moved.  

This worked previously, but for some reason the added LineShape.Endpoint.X and .Y position are offset, such that the Me.PointToScreen(testPoint).X and .Y in the MouseNearby() function are displaced from the Cursor.Position.X and .Y about 50 pixels.  Basically, the LineShape controls are appearing about plus y=50 points down on the Windows Form from their true location, causing the MouseNearby test to never be true.  There is some sort of invisible offset causing the LineShape not to be in sync with the Me.PointToScreen(testPoint).X and Y values.  What would cause a line shape to appear in a location that cannot be directly identified?   Would it be that the ShapeContainer is displaced by an invisible offset?


    Public Sub ShapeContainerMouseMoveEventHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim siSCId As Integer
        Dim myShapeContainer As ShapeContainer
        myShapeContainer = CType(sender, ShapeContainer)
        Dim myLineShape As LineShape
        ' get index of the actual ShapeContainer in ShapeContainer array
        siSCId = Array.IndexOf(mShapeContainer, sender)
    
        If siSCId > -1 Then
            myLineShape = mLineShapes(siSCId)
            If MouseIsNearBy(myLineShape.EndPoint) Then
                myLineShape.BorderColor = Color.Red
                NearLineEndPoint = True
            End If
            If MouseIsNearBy(myLineShape.EndPoint) = False Then
                myLineShape.BorderColor = Color.Black
                NearLineEndPoint = False
            End If
            If (dragStartPoint) Then
                myLineShape.StartPoint = New Point(oldStartPoint.X + e.X - oldMouseX, oldStartPoint.Y + e.Y - oldMouseY)
            End If
            If (dragEndPoint) Then
                myLineShape.EndPoint = New Point(oldEndPoint.X + e.X - oldMouseX , oldEndPoint.Y + e.Y - oldMouseY)
            End If
            myLineShape.Invalidate()
            myShapeContainer.Parent.Refresh()
        End If
    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

ASKER CERTIFIED SOLUTION
Avatar of HooKooDooKu
HooKooDooKu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lep1
lep1

ASKER

Actually did not help