-
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?