Solved

Undetectable offset between LineShape true location and visual location

Posted on 2013-01-03
2
368 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
Comment Utility
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
Comment Utility
Actually did not help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

6 Experts available now in Live!

Get 1:1 Help Now