473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How do I get a trackbar to move to a click position (like Media Player)?

I'm working on a video player app, and I want to implement a trackbar
that behaves like the one in Media Player, that is the cursor position
moves to where the user clicked instead of moving in that direction by
a fixed value. Has anyone implemented something like this before? I
haven't found anything on codeproject, or searching the .NET
newsgroups. This seems like it would be a common control type, am I
missing the easy solution?

I have been trying to make one by overridding the mouseUp event (so
that it can be either clicked or dragged) but I can't get the cursor to
move to the correct position, and the difference between the click and
where the cursor gets moved changes depending on where in the trackbar
I click.

I'm manaully building the DShow player graph in a DLL, and the UI is in
a VB app. I need full control over the graph and playback, so I don't
think I can use the Media Player object.

Thanks,
Mike

Jul 13 '06 #1
2 10095
Hi Mike,

The TrackBar has a Minimum, a Maximum, and a Value property. It also has a
slot in which the slider moves. The Minimum value is the value when the
slider is at the far left side of the slot. The Maximum value is the value
when it is at the far right side of the slot. Now, let's say for the sake of
simplicity that the Minimum is 0 and the Maximum is 100. What will the Value
be when the slider is 1/4 of the way between the left and right? 25, right.
What about when it is half-way? 50. Are you following me here?

The point where the Mouse clicks represents a pixel location that is a point
inside the TrackBar. If the TrackBar slot is 10 pixels in from the left,
you subtract 10 from the X value to get the pixel position of the slider.
The total number of pixels that spans the slider represents the total amount
between Minimum and Maximum (Maximum minus Minimum). The number of pixels
from the left edge of the slot is a fraction of the total number of pixels
that spans the slider (pixel X divided by Total Pixels). The fraction is the
same fraction as the fraction of the total amount between Minimum and
Maximum that the Value would be if the slider was positioned at that point.
If you were to set the Value to this number, the slider would be positioned
there.

So, the X xel position of the Mouse click can be converted to a Value using
the following formulas:

Maximum minus Minimum = Total (number)
Slot Right (end of Slot) (pixels) minus Slot Left (beginning of Slot) pixels
= Total (pixels)
Mouse X minus Slot Left. = Mouse Slot position (pixels)
Fraction = Mouse Slot Position divided by Total (pixels)
Mouse Position (number) = Fraction Times Total (number)

Let's assign variables to them:

MaxVal - MinVal = TotalVal
SlotEndPix - SlotStartPix = TotalPix
MouseLeftPix - SlotStartPix = MouseSlotPix
Fraction = MouseSlotPix / TotalPix
MouseNum = Fraction * TotalVal

So, all you have to do is handle the Click event of the TrackBar, and use
the math I've provided to set the Value property of the TrackBar.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
<mm*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
I'm working on a video player app, and I want to implement a trackbar
that behaves like the one in Media Player, that is the cursor position
moves to where the user clicked instead of moving in that direction by
a fixed value. Has anyone implemented something like this before? I
haven't found anything on codeproject, or searching the .NET
newsgroups. This seems like it would be a common control type, am I
missing the easy solution?

I have been trying to make one by overridding the mouseUp event (so
that it can be either clicked or dragged) but I can't get the cursor to
move to the correct position, and the difference between the click and
where the cursor gets moved changes depending on where in the trackbar
I click.

I'm manaully building the DShow player graph in a DLL, and the UI is in
a VB app. I need full control over the graph and playback, so I don't
think I can use the Media Player object.

Thanks,
Mike

Jul 13 '06 #2
Thanks, I got it working. I forgot to account for one of the offsets.

Mike
Kevin Spencer wrote:
Hi Mike,

The TrackBar has a Minimum, a Maximum, and a Value property. It also has a
slot in which the slider moves. The Minimum value is the value when the
slider is at the far left side of the slot. The Maximum value is the value
when it is at the far right side of the slot. Now, let's say for the sake of
simplicity that the Minimum is 0 and the Maximum is 100. What will the Value
be when the slider is 1/4 of the way between the left and right? 25, right.
What about when it is half-way? 50. Are you following me here?

The point where the Mouse clicks represents a pixel location that is a point
inside the TrackBar. If the TrackBar slot is 10 pixels in from the left,
you subtract 10 from the X value to get the pixel position of the slider.
The total number of pixels that spans the slider represents the total amount
between Minimum and Maximum (Maximum minus Minimum). The number of pixels
from the left edge of the slot is a fraction of the total number of pixels
that spans the slider (pixel X divided by Total Pixels). The fraction is the
same fraction as the fraction of the total amount between Minimum and
Maximum that the Value would be if the slider was positioned at that point.
If you were to set the Value to this number, the slider would be positioned
there.

So, the X xel position of the Mouse click can be converted to a Value using
the following formulas:

Maximum minus Minimum = Total (number)
Slot Right (end of Slot) (pixels) minus Slot Left (beginning of Slot) pixels
= Total (pixels)
Mouse X minus Slot Left. = Mouse Slot position (pixels)
Fraction = Mouse Slot Position divided by Total (pixels)
Mouse Position (number) = Fraction Times Total (number)

Let's assign variables to them:

MaxVal - MinVal = TotalVal
SlotEndPix - SlotStartPix = TotalPix
MouseLeftPix - SlotStartPix = MouseSlotPix
Fraction = MouseSlotPix / TotalPix
MouseNum = Fraction * TotalVal

So, all you have to do is handle the Click event of the TrackBar, and use
the math I've provided to set the Value property of the TrackBar.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
<mm*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
I'm working on a video player app, and I want to implement a trackbar
that behaves like the one in Media Player, that is the cursor position
moves to where the user clicked instead of moving in that direction by
a fixed value. Has anyone implemented something like this before? I
haven't found anything on codeproject, or searching the .NET
newsgroups. This seems like it would be a common control type, am I
missing the easy solution?

I have been trying to make one by overridding the mouseUp event (so
that it can be either clicked or dragged) but I can't get the cursor to
move to the correct position, and the difference between the click and
where the cursor gets moved changes depending on where in the trackbar
I click.

I'm manaully building the DShow player graph in a DLL, and the UI is in
a VB app. I need full control over the graph and playback, so I don't
think I can use the Media Player object.

Thanks,
Mike
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left...
3
by: MstrControl | last post by:
Greetings, I'm working on a project that requires the use of trackbar. So far so good, but I want to add that look of Windows Media Player Graphic Equalizer. Does anyone knwo how it's...
3
by: Geoff Cox | last post by:
Hello, I am using Visual C++ 2005 Express Beta 2 and cannot sort out how to use the Scroll property value for a trackBar. Under Event properties the name for the Scroll property is...
2
by: John | last post by:
Ok, something that I thought would be easy is giving me fits. Using .NET 2.0 and C# I've added a Trackbar to a form. Set some values: trackVolume.Maximum = 100; trackVolume.Minimum = 0;...
2
by: Piotrekk | last post by:
Hi. I have a trackbar. I need to set trackbar value depending on where user has clicked on the bar ( mouse_up event for example ). However avent arguments are telling me only about x and y...
1
by: DILA | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the...
3
by: homec | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the ...
6
by: xhunter | last post by:
I have this problem on my website and no matter what I have not been able to get over it, it is really getting on my nervers. it's a problem that only exists in non IE browsers. the frame work...
3
by: hurricane_number_one | last post by:
I want to be able to play/pause/next/back the tracks in whatever media player app is running. So if iTunes is running, it will receive those commands, if Windows Media Player is, it will receive...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.