Page 1 of 1

Mouse position in slider

Posted: Saturday 11th May 2019 1:38pm
by bill-lancaster
I have a slider(Slider1) and want to know the X position of the mouse, without a left or right click, when its inside the slider.
Have set Slider1 Tracking to true but the MouseMove event doesn't show anything.
Any advice would be welcome

Re: Mouse position in slider

Posted: Saturday 11th May 2019 2:37pm
by stevedee
Do you just want a pixel value for the mouse when inside the slider control or some derived value that matches the slider value.

For the simple case you could run a timer to report the mouse position:-
Public Sub Timer1_Timer()

  Me.text = Mouse.ScreenX

End
...and then make corrections based upon the position of the control on the form.
Public Sub Timer1_Timer()

  Me.text = Mouse.ScreenX - Me.Left - Slider1.Left
  If Val(Me.Text) < 0 Then
    Me.Text = 0
  Endif
  If Val(Me.Text) > Slider1.Width Then
    Me.Text = Slider1.Width  
  Endif
  
End
However, I have a feeling I'm miles away from understanding the question.

Re: Mouse position in slider

Posted: Saturday 11th May 2019 2:51pm
by cogier
Have a look at the attached code, does that help? My friend Matt is thinking that there is a bug in 'tracking'.

Image
Test2.tar.gz
(35.16 KiB) Downloaded 422 times
UPDATE: - The tracking works differently from other controls. It does not track the mouse but the slider. The help file states "Indicates that the Slider emits Change events continuously when it is moved, not just the mouse button is released."

Re: Mouse position in slider

Posted: Saturday 11th May 2019 4:58pm
by bill-lancaster
Thanks stevedee, the slider is showing the progress of an audio file playback. I want to show the exact time value when the mouse is positioned in the slider.

Thank you cogier for the demo file, I'm having trouble extracting it.
$:tar -xzf Test2.tar.gz
returns:-
gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now

Where am I going wrong?

Re: Mouse position in slider

Posted: Saturday 11th May 2019 10:45pm
by Cedron
stevedee wrote: Saturday 11th May 2019 2:37pm
...and then make corrections based upon the position of the control on the form.

...

However, I have a feeling I'm miles away from understanding the question.
That's a clever solution, somewhat hackish, but should be effective. I looked and couldn't find a better way in the Wiki.

However, I think you also want to check the Mouse.Y value so that the mouse is either on or near the slider.

Miles? I think you nailed it.

Re: Mouse position in slider

Posted: Sunday 12th May 2019 12:52pm
by cogier
Hi Bill, try this one.
Test2.7z
(34.29 KiB) Downloaded 394 times

Re: Mouse position in slider

Posted: Monday 13th May 2019 7:21am
by bill-lancaster
Thank you so much Cogier - perfect!