locked
Last question about this, I promise xD RRS feed

  • Question

  • I'm having just a couple of difficulties regarding playback for "Dim mp As Point = ClientContainer.PointToClient(MousePosition)" = these are a set of coordinates relative to my form, when trying to play this back (from a single listbox called "MouseXY"), rather than placing the cursor to the coordinates in the listbox (which from recording, are correct), the cursor shoots straight to the top left corner of the screen and then, after some seconds, moves slowly to the right and then stops. This is the code to playback the coordinates:
    Private Sub Playback_Tick(sender As Object, e As EventArgs) Handles Playback.Tick
            Dim TotalItems As Integer = MouseXY.Items.Count - 1
            Dim SelectedIndex As Integer = MouseXY.SelectedIndex
    
            If TotalItems = SelectedIndex = False Then
                Dim relativePoint = Me.PointToClient(New Point(MouseXY.SelectedIndex))
                Cursor.Position = Me.PointToClient(New Point(MouseXY.SelectedIndex))
                MouseXY.SelectedIndex = MouseXY.SelectedIndex + 1
            Else
                Playback.Enabled = False
            End If
    End Sub

    This should work, right?

    This is the previous code from the previous way of getting the coordinates, which was not ideal as the coordinates must relate to my form, not the screen (which you helped me with):

    Dim TotalItems As Integer = MouseX.Items.Count - 1
            Dim SelectedIndex As Integer = MouseX.SelectedIndex
    
            If TotalItems = SelectedIndex = False Then
                Cursor.Position = New Point _
                    (MouseX.SelectedItem, MouseY.SelectedItem)
                MouseX.SelectedIndex = MouseX.SelectedIndex + 1
                MouseY.SelectedIndex = MouseY.SelectedIndex + 1
            Else
                Playback.Enabled = False
            End If


    So you can see that I've replaced

    Cursor.Position = New Point _

    and isolated the set of coordinates to one listbox only. And, it should be noted, the coordinates are placed in curly brackets in a format like this: "{X = 505, Y = 505}"

    So, why is the cursor shooting off to the top left screen? It's strange and I can't see why it would do that... :¬| Thanks a lot

    Sunday, November 5, 2017 10:14 PM

Answers

  • So you can see that I've replaced

    Cursor.Position = New Point _

    and isolated the set of coordinates to one listbox only. And, it should be noted, the coordinates are placed in curly brackets in a format like this: "{X = 505, Y = 505}"

    So, why is the cursor shooting off to the top left screen? It's strange and I can't see why it would do that... :

    This
      If TotalItems = SelectedIndex = False Then
    is the wrong way to express what you want to do.  It should be
      If TotalItems <> SelectedIndex Then

    You are calculating RelativePoint but then not using it.  That code and variable seems unnecessary.

    This code
     Cursor.Position = Me.PointToClient(New Point(MouseXY.SelectedIndex)))

    will probably invoke this constructor https://msdn.microsoft.com/en-us/library/0f03h6z4%28v=vs.110%29.aspx? which expects a size.   You are passing a listbox item.  It's not clear what Type your listbox items are, but it appears that the conversion from listbox item to a Size is not working. You should insert a breakpoint at that line and see what results you are getting for the point that is being created.

    You may need to add some code which takes a listbox item and converts it to two integers or t a Size, then use those integers in the Point constructor. The Type for your listbox items will be the Type for the objects you are adding to the list box list.

    Or, instead of a list box, use a List(Of T) where T is a Point.  In that case, no conversion will be required, and it will not even be necessary to create a new point.

      Cursor.Position = Me.PointToClient(PositionList(SelectedIndex))



    • Edited by Acamar Monday, November 6, 2017 12:09 AM sp
    • Marked as answer by Lucy Qu Tuesday, November 7, 2017 10:12 PM
    Monday, November 6, 2017 12:00 AM