Results 1 to 4 of 4

Thread: [RESOLVED] Why is my cursor going to the wrong place ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Resolved [RESOLVED] Why is my cursor going to the wrong place ?

    Hi,

    I'm trying to start an application with the cursor in the middle of the from, close to the bottom edge. It's not anywhere close to that so I'm trying to discover why, so as a trial I'm Using: -
    Code:
    Cursor.Position = New Point(Me.Width, Me.Height )
    I would expect the cursor to go to the bottom right-hand corner of the form... It doesn't.

    To get the cursor at the bottom right-hand corner I have to use
    Code:
    Cursor.Position = New Point(Me.Width + 160, Me.Height + 36)
    which gets it as close as I can tell.

    The form is 1200, 750, I've programmed the app. to display the form size and the cursor position in a label.
    Then using :
    Code:
    Cursor.Position = New Point(1358, 778)
    running the code, the label says that the form's width is 1189, height is 742 (this is normal for a form of this size, it disregards the borders.)
    The cursor is just inside the form's bottom right-hand corner, one more pixel right or down puts the cursor on the edge with drag arrows.
    The label tells me that the cursor is at 1358,778. How can this be ? (considering the size of the form)
    Is this the 'default form instance' problem rearing it's ugly head again ?


    Poppa

    PS.
    I should mention that the form's AutoScaleMode is set to None.

    Pop
    Last edited by Poppa Mintin; Nov 17th, 2020 at 11:20 AM.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Why is my cursor going to the wrong place ?

    Cursor.Position is setting the position in screen coordinates, not coordinates in relation to your form.

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Why is my cursor going to the wrong place ?

    The main cause is Cursor.Position is in Screen coordinates and the point on a form ("Me") is in Form coordinates. The right way is:
    Code:
        Cursor.Position = PointToScreen(New Point(Me.ClientSize.Width-1, Me.ClientSize.Height-1)
    This works whatever the AutoSizeMode.

    I think it's a good idea to make a habit of using ClientSize or ClientRectangle (which exclude the border if any) instead of just Me.Width and Me.Height, because they exclude the border - even if the border style is None. The -1 is may be a bit pedantic: it makes sure that you are at bottom right of the client area, not just outside it on the border.

    BB

  4. #4

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: Why is my cursor going to the wrong place ?

    Thanks Boops Boops,
    I ought to've realised that.

    The bottom corner thing was only so that I could see exactly where the cursor was, it now goes exactly where I want it to.

    That's another one for my 'Snippets' folder.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width