-
Clicking a progress bar and making the value the mouse's position(resolved)
Hi all,
Is it possible to make it in the click event of a progress bar, make the value of the progress bar where the mouse clicked? I can't figure out how to do it.
Any help would be greatly appreciated :)
-
Re: Clicking a progress bar and making the value the mouse's position
I have another question also, and did not feel it was necessary to make a new thread. How do I get the color of the menu into a variable?
-
Re: Clicking a progress bar and making the value the mouse's position
Yes you can. I've done it before. You need to syncronize the size of the progress and width of your form. Use MouseDown and MouseMove to get values. It takes some experamenting, but it can be done.
For an example, look at the PEAK DETECT SETTINGS in this code:
http://www.planetsourcecode.com/vb/s...00518582062705
0x34
-
Re: Clicking a progress bar and making the value the mouse's position
thanks for your reply ox, but the example you gave me has about 30 or 40 items inside the zip file. What I tried doing is
VB Code:
Private Sub progressbar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MsgBox y - pb.Left
End Sub
to see what it'd give me... nothing close to what I need
-
Re: Clicking a progress bar and making the value the mouse's position
This will do the trick:
VB Code:
Private Sub ProgressBar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ProgressBar1.Value = (x * ProgressBar1.Max) / ProgressBar1.Width
End Sub
-
Re: Clicking a progress bar and making the value the mouse's position
I get the error invalid property value
-
Re: Clicking a progress bar and making the value the mouse's position
It worked fine for me, with a max of 100.
-
Re: Clicking a progress bar and making the value the mouse's position
Hmmm.... Works fine for me. The code I gave is for a horizontal progress bar. It would probably fail for verticle. Use this instead if it's veriticle:
VB Code:
Private Sub ProgressBar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ProgressBar1.Value = ((ProgressBar1.Height - y) * ProgressBar1.Max) / ProgressBar1.Height
End Sub
-
Re: Clicking a progress bar and making the value the mouse's position
Mine is horizontal. I does not work for me. The max is 100, and Min 0..? :confused:
-
1 Attachment(s)
Re: Clicking a progress bar and making the value the mouse's position
Here's my project, with some code commented out. Please take a look I don't know what's wrong.
-
1 Attachment(s)
Re: Clicking a progress bar and making the value the mouse's position
Here is what happens for me when I do this:
I clicked on the right edge of the button with the Play Icon
-
Re: Clicking a progress bar and making the value the mouse's position
There wasn't enough files included to try to run it, but the code is firing correctly. It doesn't move the position of the song, and I think the timer is going to move it right back. You would have to incorporate the song position into it.
-
Re: Clicking a progress bar and making the value the mouse's position
that works for you?? it doesn't work at all for me on my computer.
-
Re: Clicking a progress bar and making the value the mouse's position
I set a breakpoint, and clicked on the bar. x was 2200 max was 100 and i forget what width was. of course, nothing was playing.
-
Re: Clicking a progress bar and making the value the mouse's position
I beleive this is the fomula:
VB Code:
Private Sub ProgressBar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ProgressBar1.Value = x / (ProgressBar1.Width / ProgressBar1.Max)
End Sub
-
Re: Clicking a progress bar and making the value the mouse's position
Bruce, when I do this, nothing happens. I am using VB6 by the way
-
Re: Clicking a progress bar and making the value the mouse's position
Wouldn't you multiply?
VB Code:
Private Sub ProgressBar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ProgressBar1.Value = x [COLOR=Red]*[/COLOR] (ProgressBar1.Width / ProgressBar1.Max)
End Sub
-
Re: Clicking a progress bar and making the value the mouse's position
For that I need a number 1 - 100
pb.Value = x [x = 60]* (pb.Width[width=489] / pb.Max[max=100])
that will give me the number 293.4 which is too big...
-
Re: Clicking a progress bar and making the value the mouse's position
Oops. That's right. What was wrong with the code from yesterday?
-
Re: Clicking a progress bar and making the value the mouse's position
Oh shoot! hold on a sec I put it in wrong.
-
Re: Clicking a progress bar and making the value the mouse's position
You plugged your values in wrong. The code I posted last night can never return a value greater than the .Max.
-
Re: Clicking a progress bar and making the value the mouse's position
ProgressBar1.Value = (x * ProgressBar1.Max) / ProgressBar1.Width
x = (60 *100) / 489
x = 12. something
That should work, but it doesn't???
-
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by Comintern
You plugged your values in wrong. The code I posted last night can never return a value greater than the .Max.
I am definately doing something wrong, when I click approximately in the middle I get the number 711 returned.
-
Re: Clicking a progress bar and making the value the mouse's position
I'll attach the demo - it works... brb
-
1 Attachment(s)
Re: Clicking a progress bar and making the value the mouse's position
-
Re: Clicking a progress bar and making the value the mouse's position
You're right it works in that and any new project I start, just not in this one! I have no idea why and I'm going to shoot myself now.
-
Re: Clicking a progress bar and making the value the mouse's position
Aren't you moving the progress bar in your timer? You would have to advance the position of the song when you click the progress bar.
-
Re: Clicking a progress bar and making the value the mouse's position
Your right! So Now I've got this, but the formula doesn't return values between 1 - 100
VB Code:
m_objMediaPosition.CurrentPosition = (x * pb.Max) / pb.Width
-
Re: Clicking a progress bar and making the value the mouse's position
Oh, and when I start the song, the max of the progress bar changes to the length of the song!
-
Re: Clicking a progress bar and making the value the mouse's position
Then set the currentposition to the value of the pb!
-
Re: Clicking a progress bar and making the value the mouse's position
Is your max higher than 100? All it does is calculate a simple ratio like this:
Code:
x .Value
------ = ------
.Width .Max
.Value * .Width = x * .Max
.Value = (x * .Max)/.Width
-
Re: Clicking a progress bar and making the value the mouse's position
I do, but when I use the equation it does not give me the right numbers for some reason :cry:
-
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by Comintern
Is your max higher than 100? All it does is calculate a simple ratio like this:
Code:
x .Value
------ = ------
.Width .Max
.Value * .Width = x * .Max
.Value = (x * .Max)/.Width
yes the max is higher than 100, the max depends on the length of the song.
-
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by paralinx
Oh, and when I start the song, the max of the progress bar changes to the length of the song!
I'd set the .Max to 100 and track it independent of the song length. To set the progress in the timer, find the percent complete and set that to the progressbar.
-
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by Comintern
I'd set the .Max to 100 and track it independent of the song length. To set the progress in the timer, find the percent complete and set that to the progressbar.
Actually I still think the .Max should be irrelevent, but I had another thought. What version of the progress bar are you using? I think Version 6 reports x in pixels and it's .Width in twips, and version 5 reports both in twips. The code above can't ever have a value higher or lower than the .Max unless x is higher or lower than the .Width, so make sure the scale mode is the same for both before you do the calc.
-
Re: Clicking a progress bar and making the value the mouse's position
For my own curiosity... why wouldn't you use the length of the song as the .Max value of the PB (or have I not read each post in detail)?
-
Re: Clicking a progress bar and making the value the mouse's position
Quote:
Originally Posted by Bruce Fox
For my own curiosity... why wouldn't you use the length of the song as the .Max value of the PB (or have I not read each post in detail)?
thats what im doing
-
Re: Clicking a progress bar and making the value the mouse's position
can someone come up with a way to do this without the max being only 100??
-
Re: Clicking a progress bar and making the value the mouse's position
Use the progress bar value as the current position. you won't have to translate anything!
-
Re: Clicking a progress bar and making the value the mouse's position
That will be too much work to fix a simple problem. I have pretty much everything done except for being able to change the sond position by clicking the progress bar.
By the way Dglienna, do you know a way where I can change the computer's volume control that is found in the bottom right hand corner?
-
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. :)