Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by paralinx
can someone come up with a way to do this without the max being only 100??
As I mentioned :) Set the .Max = SongLength
That way the PB 'ticks' are representative of the song play postion....
You would set the .Max at song load, and update the .Value based on the Song position.
Does that make sense? Or, am I missing the obvious?
Re: Clicking a progress bar and making the value the mouse's position
Wouldn't it be so much easier to ditch the progressbar and use a picturebox instead? Simply set the ScaleWidth property to the length of the song and to update the progress in it simply do this:
VB Code:
Public Sub ProgressValue(pic As PictureBox, nValue As Long)
pic.Line (nValue, 0) - (pic.ScaleWidth, pic.ScaleHeight), pic.BackColor, BF
pic.Line (0, 0)-(nValue, pic.ScaleHeight), vbBlue, BF
End Sub
The AutoRedraw property should be set to True.... Now in the MouseDown event use the X value directly to change the position in the current song and to update the progress in the picturebox.
Re: Clicking a progress bar and making the value the mouse's position
I was gonna post about ScaleMode until I read JA's post. paralinx, you probably changed the ScaleMode property of your form, which is why it works with new projects.
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by paralinx
do you know a way where I can change the computer's volume control that is found in the bottom right hand corner?
You shouldn't alter that unless you really have to. Whatever method you're using to play audio, that should have a way of controlling its own volume.
Re: Clicking a progress bar and making the value the mouse's position
I'd need a way to update the picture box during the song like the progress bar then. And I have no idea how.
Re: Clicking a progress bar and making the value the mouse's position
You update the ProgressBar now by simply setting the Value property right? Well instead of setting the Value property call the ProgressValue Sub I showed above.
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by paralinx
I'd need a way to update the picture box during the song like the progress bar then. And I have no idea how.
As your no doubt aware you will need to be constantly cycling this app so that you can update the statusbar/picturebox, display the current song time, maybe time remaining. To do that you could use a Timer, a Loop etc. I think
you mentioned
that you are using a Timer - is that right?
To put it simply, you will need something like:
VB Code:
'A.
Private Sub Timer1_Timer()
'Main code executes here (updates labels, progressbars etc)
End Sub
'OR
'B.
Do Until Stop
'Main code executes here (updates labels, progressbars etc)
Loop
Therefore, can you post the code that you have that performs the pseudo function above :)
Re: Clicking a progress bar and making the value the mouse's position
Joacim, I am working with your code, and it will only update the picturebox once. Am i doing something wrong?
VB Code:
Private Sub tmrTimer_Timer()
Dim nReturnCode As Long
Dim dblPosition As Double
On Local Error GoTo ErrLine
Call ProgressValue(Pic, m_objMediaPosition.CurrentPosition)
End Sub
Public Sub ProgressValue(Pic As PictureBox, nValue As Long)
Pic.Line (nValue, 0)-(Pic.ScaleWidth, Pic.ScaleHeight), Pic.BackColor, BF
Pic.Line (0, 0)-(nValue, Pic.ScaleHeight), vbBlue, BF
End Sub
Re: Clicking a progress bar and making the value the mouse's position
Have you set the ScaleWidth of the picturebox to the length of the song? You might need to also set the ScaleMode property to vbUser (this can be done during design time). The ScaleWidth will then act as the Max property.
Re: Clicking a progress bar and making the value the mouse's position
Whats wrong with the slider from the microsoft common controls? Or even a scroll bar?
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by Joacim Andersson
Have you set the ScaleWidth of the picturebox to the length of the song? You might need to also set the ScaleMode property to vbUser (this can be done during design time). The ScaleWidth will then act as the Max property.
Ok I got it working now. Would you know the code for when I click anyone on the picture box that i could set the position of the blue line to where the mouse click was?
Re: Clicking a progress bar and making the value the mouse's position
In the MouseDown or MouseUp event use the X argument to determent what value you should set the CurrentPosition of the song to. The Timer event will then update the picture box.
Re: Clicking a progress bar and making the value the mouse's position
Holy cow! It's a miracle I got it to work finally!
Thanks every so much for all you're help!
Here's the final code that I used
VB Code:
m_objMediaPosition.CurrentPosition = (X * m_objMediaPosition.Duration) / Pic.ScaleWidth
Re: Clicking a progress bar and making the value the mouse's position(resolved)
Well, I'm glad you got it working :) However if you would have set the ScaleWidth of the picture box to the duration of the song whenever a new song is selected you shouldn't need to do the above calculation. :)