finding position of mouse pointer..in relation to the scale size

andreww
01-13-2002, 08:07 AM
this is what i am using

------------------------------------------------------------------------------------
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Integer
y As Integer
End Type

Dim MousePoint As POINTAPI
------------------------------------------------------------------------------------
GetCursorPos MousePoint
ScreenToClient Picture1.hwnd, MousePoint
------------------------------------------------------------------------------------


this is to get the mouse pointers position within a picture1 box

but my problem is that I have scaled the picture box like this

Board.Scale (0, 0)-(6, 6)

but the mouse position outputted from the code above gives only in pixels, not in the scale that i have set
does anyone know how to fix this? or is there another method?

basically i want to be able to move a mousepointer around some tiles and everytime the pointer is in a tile to beable to detect which tile it is in.

Teric
01-14-2002, 09:42 AM
You can detect which tile you're over by doing something like this:

1. You have a 7 x 7 tile box (0-6, 0-6)

2. You know the actual .top and .left of the picture box (for example, let's say the .top is 500 and the .left is 250)

3. You know the actual .width and .height of the picture box (for example, let's say the .width is 350 and the .height is 350)

4. You know the actual position of the mouse (for example, let's say the mouse's X is 587 and the mouse's Y is 811)

5. You can figure out the mouse's horizontal tile position by using the following equation. This will use the \ operator for integer division. Basically what I'm doing is dividing the mouse's X position relative to the picture box by the width of a tile.

TileX = (MouseX - PictureBox.Left)\(PictureBox.Width/7)

In this example, you would get

TileX = (587 - 250)\(350/7) = 137\50 = 2

Which means that your mouse is pointing to the third tile from the left, or index 2 (0, 1, 2).

6. You can figure out the mouse's vertial tile position using a similar equation.

In this example, you would get

TileY = (811 - 500)\(350/7) = 311\50 = 6

Which means that your mouse is pointing to the 7th tile from the top, or index 6 (0, 1, 2, 3, 4, 5, 6)

THUS, in this example, your mouse is pointing to the tile at index (2,6)

andreww
01-15-2002, 11:47 PM
'You just need to start a form and make 2 labels


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Caption = Int(X)
Label2.Caption = Int(Y)
End Sub

Private Sub Form_Resize()
Cls
Me.Scale (1, 1)-(7, 7)
For i = 1 To 6
Line (1, i)-(6, i)
Line (i, 1)-(i, 6)
Next i
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum