Cursor Position

B

bgreer5050

I have a text box: mouseposition

When the mouse is clicked on a form I would like the value of
mouseposition.text to represent the position of the mouse.

Thanks
 
D

Dirk Goldgar

I have a text box: mouseposition

When the mouse is clicked on a form I would like the value of
mouseposition.text to represent the position of the mouse.

This could be relatively simple, depending on what you need. You'd use
the MouseDown event, but be aware that the form itself has a MouseDown
event and each section of the form has a MouseDown event. The form's
event isn't much good, as it pretty much only fires if someone presses a
mouse button on the record selector. probably you want to use the
form's Detail section's event:

'----- start of code -----
Private Sub Detail_MouseDown( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)

Me!MousePosition = X & ", " & Y

End Sub

'----- end of code -----
 
D

Damon Heron

If that is all you want, then

Private Sub Detail_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim z As String
z = CStr(X) & ", " & CStr(Y)
Me!mouseposition = z
End Sub

HTH
Damon
 
D

Damon Heron

Dirks is better, but for some reason, the first time I tried that, it would
not work, so I added the CStr... I must have just left out an ampersand or
something.... D*U*H

Damon
 
D

Dirk Goldgar

Damon Heron said:
Dirks is better,

Nah, they're pretty much the same. Some people advocate always making
type conversion explict, as by using CStr the way you did. I've never
felt that's necessary in VB, unless the conversion is obscure in some
way, but it's a point that can be argued.
but for some reason, the first time I tried that, it
would not work, so I added the CStr... I must have just left out an
ampersand or something....

Probably some typo, but don't sweat it. I was amused that we posted
essentially the same thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top