|
-
Jun 17th, 2010, 06:33 AM
#1
Thread Starter
Member
[Request] I'd like to ask someone to help me with a point in the screen
Hello people, i'm new here in VBForums, I dont know if its the right place to place a request, if dont, please move it.
Lets go to the problem:
I have a point in the screen that i want to be the same as the resolution changes. I'll explain better. Look out the example
Example:
HTML Code:
Dim point As New Point
Dim point1 As New Point
Dim x As Integer, y As Integer
Dim amaisx As Integer = 0
Dim amaisy As Integer = 0
point = Cursor.Position
point1 = Screen.PrimaryScreen.Bounds.Size
If point1.X <> 1280 Or point1.Y <> 800 Then
amaisx = (1280 - point1.X) * -1
amaisy = (800 - point1.Y) * -1
End If
x = point1.X - (point1.X - 120 + amaisx) '120 is the x cordenate of the position I want, and the same for y.
y = point1.Y - (point1.Y - 540 + amaisy)
SetCursorPos(x, y)
Here I'm trying to get the diference between my own resolution(1280x800[its a notebooks resolution]) and the point in this resolution that i want the mouse to be is 120,540.
But when I change the screen size it doesnt work of corse.
Are there anyone that can help me with it?
And sorry if my english isnt the best u have ever seen.
-
Jun 17th, 2010, 11:06 AM
#2
Re: [Request] I'd like to ask someone to help me with a point in the screen
 Originally Posted by henriqueshb
And sorry if my english isnt the best u have ever seen.
Oh, it's not bad.
What I would do would be to go about the problem in a different fashion. First off, you want a position of X= 120, Y = 540 when the screen resolution is 1280x800.
Therefore, the X point is 120/1280 of the screen, and the Y point is 540/800 of the screen:
Code:
Dim xRatio = 120/1280
Dim yRatio = 540/800
Naturally, you could calculate those out, as they are not really variable, but might as well leave it like this for clarity.
Now, these ratios should be true for any screen resolution. Therefore:
Code:
Dim newX = point1.X * xRatio
Dim newY = point1.Y * yRatio
Should work for any reasonable resolution, though it could get off a bit if the resolution dropped to something impossibly small. Notice that this will also work for 1280x800, because, if you put those values into the second set of code for point1.X and point1.Y, your newX will be 120, and your newY will be 540, which is just as they should be.
My usual boring signature: Nothing
 
-
Jun 18th, 2010, 05:57 AM
#3
Thread Starter
Member
Re: [Request] I'd like to ask someone to help me with a point in the screen
Shaggy, thanks for the help, now my program is running great.
Thank you man.

Please and admin could post that its resolved.
Thanks at all.
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
|