Mouse position in slider

Post Reply
bill-lancaster
Posts: 63
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Mouse position in slider

Post by bill-lancaster » Saturday 11th May 2019 1:38pm

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

stevedee
Posts: 120
Joined: Monday 20th March 2017 6:06pm

Re: Mouse position in slider

Post by stevedee » Saturday 11th May 2019 2:37pm

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.

User avatar
cogier
Site Admin
Posts: 302
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Mouse position in slider

Post by cogier » Saturday 11th May 2019 2:51pm

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 31 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."

bill-lancaster
Posts: 63
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Mouse position in slider

Post by bill-lancaster » Saturday 11th May 2019 4:58pm

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?

User avatar
Cedron
Posts: 100
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: Mouse position in slider

Post by Cedron » Saturday 11th May 2019 10:45pm

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.
.... and carry a big stick!

User avatar
cogier
Site Admin
Posts: 302
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Mouse position in slider

Post by cogier » Sunday 12th May 2019 12:52pm

Hi Bill, try this one.
Test2.7z
(34.29 KiB) Downloaded 39 times

bill-lancaster
Posts: 63
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Mouse position in slider

Post by bill-lancaster » Monday 13th May 2019 7:21am

Thank you so much Cogier - perfect!

Post Reply