Solved

Undetectable offset between LineShape true location and visual location

Posted on 2013-01-03
2
370 Views
Last Modified: 2013-01-04
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

0
Comment
Question by:lep1
2 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 55 total points
ID: 38741716
Are you sure you're testing the correct end of the line?  

In other words, is it possible that what you THINK is the EndPoint is really the StartPoint and visaversa?
0
 

Author Closing Comment

by:lep1
ID: 38745897
Actually did not help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now