Solved

Undetectable offset between LineShape true location and visual location

Posted on 2013-01-03
2
374 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
[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 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…

737 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