By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Rectangle Marker

P: n/a
I'm trying to make a rectangle follow my mouse along the X axis.

For some reason, the rectangle toggle between two places on my form, both
somewhat proportional from where I first click, but neither in line with the
mouse pointer. It's as if at:
* one pixel X=how far the mouse has moved from the point it clicked, the
* next pixel X=current X position minus how far the mouse has moved.

Here's my code.

Private Sub rctMarker_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If (Button And acLeftButton) 0 Then
rctMarker.Left = X
End If
End Sub

Am I doing this correctly, or am I supposed to reference to the forms X
reference?
Thanks in advance.
Dom
Mar 17 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DFS
Dominic Vella wrote:
I'm trying to make a rectangle follow my mouse along the X axis.

For some reason, the rectangle toggle between two places on my form,
both somewhat proportional from where I first click, but neither in
line with the mouse pointer. It's as if at:
* one pixel X=how far the mouse has moved from the point it clicked,
the * next pixel X=current X position minus how far the mouse has moved.

Here's my code.

Private Sub rctMarker_MouseMove(Button As Integer, Shift As Integer,
X As Single, Y As Single)
If (Button And acLeftButton) 0 Then
rctMarker.Left = X
End If
End Sub

Am I doing this correctly, or am I supposed to reference to the forms
X reference?

This should center the rectangle on your mouse, and move it as you want:

rctMarker.Left = rctMarker.Left + X - (0.5 * rctMarker.Width)
Mar 17 '08 #2

P: n/a
Ohhh, I'm supposed to re-reference to my rctMarker.Left. How interesting.

Thanks.
Dom

"DFS" <nospam@dfs_.comwrote in message
news:g9******************@bignews2.bellsouth.net.. .
Dominic Vella wrote:
>I'm trying to make a rectangle follow my mouse along the X axis.

For some reason, the rectangle toggle between two places on my form,
both somewhat proportional from where I first click, but neither in
line with the mouse pointer. It's as if at:
* one pixel X=how far the mouse has moved from the point it clicked,
the * next pixel X=current X position minus how far the mouse has moved.

Here's my code.

Private Sub rctMarker_MouseMove(Button As Integer, Shift As Integer,
X As Single, Y As Single)
If (Button And acLeftButton) 0 Then
rctMarker.Left = X
End If
End Sub

Am I doing this correctly, or am I supposed to reference to the forms
X reference?


This should center the rectangle on your mouse, and move it as you want:

rctMarker.Left = rctMarker.Left + X - (0.5 * rctMarker.Width)


Mar 17 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.