Click here to Skip to main content
12,892,015 members (54,172 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 16 Mar 2009

Rating Stars for Windows Media Player

, 16 Mar 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
How to create stars to display the UserRating property in WMP.


This small User Control displays the rating of a music file. Progress bars display one star with 20% rating, but the ratings of the AxWindowsMediaPlayer control are different, and not very logical. That's why I coded this small User Control.


When I tried to display the rating of a media file with a progress bar, I got very weird results. I searched the Internet, but didn't really find a solution. What I did find was an article on MSDN about how the UserRating attribute works. I decided to try to write a small class, and publish it here, to help people with the same problem as me.

I'm just 16 years old, and have two years of programming experience, but never published my code on a site like CodeProject. I have learned a lot from this project, but I hope I can learn even more from your comments on the code :-)

Using the code

First, I had to think about how to display the right star with the right rating. Because I am not that good with GDI, I created two panels which contain five stars each. With a lot of trying, testing, and thinking, I got what I searched for.

If track <= 12 Then
    Panel1.Width = (track / 12) * _Star.Width
ElseIf track > 12 And track < 87 Then
    Panel1.Width = _Star.Width + ((((track - 12) / 24)) * _Star.Width)
ElseIf track >= 87 Then
    Panel1.Width = (_Star.Width * 4) + ((((track - 87) / 12)) * _Star.Width)
End If

track is the value of the UserRating. I figured out that the first star has a value of 12, the middle stars 24, and the last star 12 again. So, the system above shows the right star with the right rating, at the right moment. If not all the stars are needed, they are just "cut off" by the panel's width, and the user sees the second panel beneath that displays the gray stars.

Next, I created a nice mouse-over function which you can enable and disable in the property RateEnabled. When this property is enabled, the stars "glow" when the mouse hovers over them, and with a click, you can set a rating. When this happens, the custom event OnRate will be fired, with the new rating. You can also change the standard images with the other ones.


All the custom properties and events of my class

Points of interest

I'd never created a User Control before with a custom event. I have learned some new stuff. This is also my first contribution to The Code Project, and I hope it is appreciated. Comments are welcome, there is always more to learn for me.


  • 13th March, 2009: Initial post.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 16 Mar 2009
Article Copyright 2009 by LegoMindstorms
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid