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

x
?
Solved

Undetectable offset between LineShape true location and visual location

Posted on 2013-01-03
2
Medium Priority
?
378 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 110 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

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