Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse Position

Status
Not open for further replies.

leckie

Programmer
Apr 19, 2001
65
0
0
GB
is there a way of finding/storing your mouse position (x, y) at the time of "on-click" or "mouse Up" ?, when using a continuos forms ?

regards
Leckie
 
You can get the current position of the mouse, in Screen Coordinates, at any time using the GetCursorPos API. In your situation, I would probably put the call in the MouseDown event of the Textbox.

In a module, declare the following public items:
Code:
Public Type POINTAPI
    tLng_Xloc  As Long
    tLng_YLoc  As Long
End Type

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
And then in the Mouse Down event:
Code:
Private Sub txtTextBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

   Dim MouseLocation As POINTAPI
   
   GetCursorPos MouseLocation
   
   MsgBox "Cursor at " & Trim(MouseLocation.tLng_Xloc) & ", " & Trim(MouseLocation.tLng_YLoc)
   
End Sub
Remember, the result will be in screen coordinates.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
on the MouseUp event, the mouse position is automatically passed into the event. They are stored in the variables X and Y.
 
In most cases jason246day, I would completely agree with you, but in this case, that fact that we're inside of a continuous form throws a monkey wrench into the equation. The X and Y coordinates supplied in the MouseUP (and MouseDown) are relative to the textbox you click in, thus you'll get the same values if you click in the textbox on the first row of the continuous form, and in the last row of the continuous form (assuming the same spot in the textbox). That's why, in this case, I think the API may be preferable.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi CajunCenturion

have put the code in as suggested but have error on

GetCursorPos

sub or function not defined . .

Leckie
 
forget last comment, Me Made Booboo . .

it works fine . .

thankyou . .
 
Hi CajunCenturion

I still have put the code in as suggested but have error on

GetCursorPos

sub or function not defined . .

Leckie
 
Hi CajunCenturion

it's all working fine now . . thank you . .

it helps when you copy all the code you suggested . .

my fault . .

Leckie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top