473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10189
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.goo glegroups.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.goo glegroups.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
32646
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 mouse click and the button under the mouse is clicked. Yours, Jonas
3
5872
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 implemented? I'd like to add both variations, the one smoothly and the other more sharply in addition to the standard behaviour (each trackbar moves disconnected from the others.
3
5399
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 trackBar1_Scroll so how do I print out the Scroll value?
2
18892
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; trackVolume.TickFrequence = 25; Then I added an event for the value:
2
2724
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 position and so on... If i had hittest method i could try to work it out... Maybe you will know how to do described task? Regards PK
1
4544
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 right-click option in the embedded Real & Quick Time players, because I don't want the viewers to download the video but to view it while streaming.
3
2566
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 right-click option in the embedded Real & Quick Time players, because I don't want the viewers to download the video but to view it while streaming.
6
5694
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 of my website is php and lets say here is how the player is shown with very simple syntaxes: <OBJECT id="VIDEO" width="'.$x.'" height="'.($y+60).'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject"> <param...
3
5693
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 those commands, and so on, just like my multimedia keyboard does. I can't find any way to do this. I have tried sending: System.Windows.Forms.Keys.MediaPlayPause, System.Windows.Forms.Keys.MediaPreviousTrack, ect. but it didn't do anything. Is...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.