Results 1 to 6 of 6

Thread: SetCursorPos question

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    SetCursorPos question

    hi


    I coded a program And it works on my computer. But i want to use it on my sisters computer...

    I use the SetCursorPos(X,Y) to move the mouse. One problem the screenresolution of my pc is diferent form my sisters computer.


    So i tried to use this code:

    ex: SetCursorPos(me.location.x = 532, me.location.y = 234)

    so i want to generation the position of my mouse on my form.
    So if i click my button i need to go to somewhere on my form. but it need to get the cordinates from my form and not form my computerscreen.

    sorry for my bad english ... I hope you understand my problem.

    greetings

  2. #2
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: SetCursorPos question

    use :

    Code:
       System.Windows.Forms.Cursor.Position
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    Re: SetCursorPos question

    thnx and how do you define the position? can you please give an example how to use the code.

    thnx!

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

    Re: SetCursorPos question

    Cursor.Position gives you a point in screen coordinates. You can turn that into a point relative to a given control using PointToClient. To get the cursor position in Form coordinates, for example, you would use:
    vb.net Code:
    1. Dim p As Point = Windows.Forms.Cursor.Position
    2. Dim formPosition As Point = Me.PointToClient(p)
    Similarly, to get the position relative to PictureBox1 it would be PictureBox1.PointToClient(p).

    You can do the reverse with PointToScreen. For example, to get point(200, 100) on the form in screen coordinates:
    vb.net Code:
    1. Dim screenPosition As Point = Me.PointToScreen(New Point(200, 100))

    groet, BB

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    Re: SetCursorPos question

    mm it doensn't work. I add a new button

    and ad the code

    Code:
    Dim screenPosition As Point = Me.PointToScreen(New Point(10, 20))

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

    Re: SetCursorPos question

    Maybe I didn't read your original question well enough (although it was a bit hard to understand)

    If you want to move the mouse pointer to screen pixel (10, 20), you do this:
    vb.net Code:
    1. Cursor.Position = New Point(10, 20)

    If you want to move the mouse pointer to point (-50, -50) of your Form client area, you can do this:
    vb.net Code:
    1. Cursor.Position = Me.PointToScreen(New Point(-50, -50))
    As you can see, the point does not actually have to be on the form.

    Normally there is no need to spell out System.Windows.Forms.Cursor.Position in full.

    I hope this answers your question, BB

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