|
-
Nov 24th, 2009, 05:56 PM
#1
Thread Starter
Member
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
-
Nov 24th, 2009, 09:47 PM
#2
Fanatic Member
Re: SetCursorPos question
use :
Code:
System.Windows.Forms.Cursor.Position
-
Nov 25th, 2009, 02:50 AM
#3
Thread Starter
Member
Re: SetCursorPos question
thnx and how do you define the position? can you please give an example how to use the code.
thnx!
-
Nov 25th, 2009, 04:10 AM
#4
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:
Dim p As Point = Windows.Forms.Cursor.Position 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:
Dim screenPosition As Point = Me.PointToScreen(New Point(200, 100))
groet, BB
-
Nov 25th, 2009, 01:13 PM
#5
Thread Starter
Member
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))
-
Nov 25th, 2009, 01:52 PM
#6
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:
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|