473,418 Members | 2,020 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,418 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 10110
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.