Results 1 to 36 of 36

Thread: Star Rating Control

  1. #1

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Star Rating Control

    *UPDATED* 4/15/2012 - Overrides OnPaint instead of handling paint, so that graphics show up at design time. Thank you minitech for the suggestion!

    I found the need for a simple, yet good looking Star Rating control. I haven't made a user control since I was programming in VB5, so this was quite a challenge for me.

    If you use my control, please reply or send me a pm to let me know! I love knowing when I help someone!
    Its here for you to use, no need to contact me if you need it. I just like knowing (it makes me proud)

    The control uses GDI+ to draw the stars from images.
    Moving the mouse highlights what stars can be chosen.


    The Control Contains 7 Custom Properties:
    1. StarCount as Integer - (Number of stars / Highest possible rating)
    2. Value as Integer - (Number of Stars Lit)
    3. StarHeight as Integer
    4. StarWidth as Integer
    5. StarGold as Image - (optional Image to override the default Star Image)
    6. StarGray as Image - (optional Image to override the default Star Image)
    7. DisplayOnly as Boolean - (when True it disables the control from updating on MouseOver or Click)

    (StarHeight and StarWidth adjust the visible size of the Stars. That way the control can be used when multiple sizes are needed)
    (Both StarGold and StarGray must be valid or neither will be replaced. You can set them to (none) to return to the default stars)

    It also Contains one Custom Event:
    ValueChanged(Value, UserChanged as Boolean) - Raised whenever the Value is changed
    UserChanged was added so you will know if the value was changed by code or by clicking on it.
    That will allow you to change the appearance of the control without messing up numbers in your program.

    To use the control, open the project (made in VS2010 express) and build it. Then open your project, right click on the toolbox, and choose "Choose Items...". Under ".Net Framework Components" Navigate to the Bin Folder of the Control Project and add it. You can then use the control like any other.



    If you have any problems loading, building, or testing this control, please let me know. Its my first in .net and I want to get it working.

    UPDATE: I added a DisplayOnly Property so that you could disable user input
    It works well if you just want to show a rating, rather than set one.

    I also commented the entire project.
    Attached Files Attached Files
    Last edited by stepdragon; Apr 15th, 2012 at 12:39 AM.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  2. #2
    New Member
    Join Date
    Apr 2012
    Posts
    5

    Re: Star Rating Control

    hi. i am using ur code, but y d design is empty?how to use this rating control?

  3. #3

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    The code uses GDI+ to draw the stars. That means that if you are in design-mode of the control it will look blank. Are you you using it correctly? What you should first do is open my project, and compile it. That will generate a dll which you can then import into your project by right clicking on the control toolbox and choosing select controls. From there you search for the dll in the dialogue.

    Sorry for the short reply I'm using my phone. Let me know if you have any other problems, I will get back to you.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  4. #4
    New Member
    Join Date
    Apr 2012
    Posts
    5

    Re: Star Rating Control

    o ya i will try it out thanks. btw, u know how to update its average rating everytime user rate it?

  5. #5

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by geniyin View Post
    o ya i will try it out thanks. btw, u know how to update its average rating everytime user rate it?
    How to have it show an average rating every time someone rates it? sure

    use the event 'ValueChanged' to detect whenever the user chooses a value, and then add that value to a list you have of all users, do some simple math and then display the result by changing the value manually...

    Its been a while since I've looked at the code of my control. If it throws 'ValueChanged' each time you change it by code, then you can simply use a boolean to ignore each time you set it progmatically. I'll add that feature to the control itself soon, because that's a good idea.


    Keep in mind though, that using the same control for choosing a rating, and for showing an average, could confuse your users. They might get confused when they click on 5 stars, and then it shows 3 stars (the average of all the ratings). It may be a better idea to use more than one control. One for your rating, and one to display the average (using the DisplayOnly property)

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  6. #6
    New Member
    Join Date
    Apr 2012
    Posts
    5

    Re: Star Rating Control

    ya that's a good idea. but i m kinda not sure i can work it out anot. haha. thanks anyway.for your time.

  7. #7

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    what's hard to work out? Let me know where you're at, and I'll help out.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  8. #8
    New Member
    Join Date
    Apr 2012
    Posts
    5

    Re: Star Rating Control

    so v nid to create a database to store each rating for each object right? so to save and get its average from database each time d project is compile?

  9. #9

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    or you could simply use a list or array. What are you trying to do in your program?

    Make a thread in the VB.Net section to continue with this. The codebank isn't the place to do problem solving. Then come here and post a link to your question so I can follow you, (and so others on this thread will find your answer once its solved)

    I also just changed my control so you will know if the value was changed by code or by the user. I'll upload it in a minute.

    First post has been updated. I suggest you download the new version because the UserChanged event will help you with what you're doing. Here's an example of how to use the new code:

    vb.net Code:
    1. Private Sub StarRate1_ValueChanged(ByVal Value As Integer, ByVal UserChanged As Boolean) _
    2.                                    Handles StarRate1.ValueChanged
    3.         If UserChanged = True Then
    4.             MsgBox("By the User", , "Changed!")
    5.         Else
    6.             MsgBox("By Code", , "Changed!")
    7.         End If
    8.     End Sub
    Last edited by stepdragon; Apr 10th, 2012 at 04:31 PM.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  10. #10
    New Member
    Join Date
    Apr 2012
    Posts
    5

    Re: Star Rating Control

    ok thanks anyway. actually i am doing a self order system for a restaurant. so maybe doing food rating for user.

  11. #11
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Star Rating Control

    If you override OnPaint instead of handling Paint, you can have the GDI+ drawings show up in the designer, too. Anyway, well done! Five stars

  12. #12

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by minitech View Post
    If you override OnPaint instead of handling Paint, you can have the GDI+ drawings show up in the designer, too. Anyway, well done! Five stars
    I did not know that.......

    OMFGTY

    Updloading an updated version right now!

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  13. #13
    New Member
    Join Date
    Apr 2012
    Posts
    4

    Re: Star Rating Control

    Registered just to say thanks. Job well done!
    I was just about to add a rating feature in my app and this post popped up in Google. Saved me some work.

    Will try to merge dll with my main app using ilmerge unless anybody has an easier solution? I would like to avoid yet another dll to bundle with my app that currently is portable.

  14. #14
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Re: Star Rating Control

    Hi Stepdragon,

    first of all I want to thank you for this fantastic Control.
    I changed the Control a little bit and added properties to display halfstars and with doubleklick to display a red star with a value of -1 .. all works fine. But now I have a binding problem.

    In design time I bind den Value to a Database. The Stars then display the binded value. When I change the rating with the StarControl nothing is saved (in Dataset)... when i change the value in a binded textbox the new value is saved. I added this to the Control but nothing happens:
    <System.ComponentModel.DefaultBindingProperty("Value")> _

    What's my failure?

  15. #15

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Can you post your modified control? I'll take a look at it. I know its been a few months, but I never noticed an email notification for this post. sorry.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  16. #16
    New Member
    Join Date
    Apr 2012
    Posts
    2

    Re: Star Rating Control

    Hi Stepdragon,
    sorry for the long time to answer.

    Here's a little Code to test the DataGridViewStarRateColumn. Unforunitly it doesn't work the way i like.
    StarRateTester.zip

    In the Sample the lower DGV is the one with der Starrate Control. Click on a Rating and see the Control.

    I like to have a Control to display decimal values als Stars in a Datagridview and want to have the ability to change the Value by clicking on the stars. The only thing that work is when you click on a Rating the Control is displayed...but when you change the value and leave you get an error.

    I have no more Idea what i could do. It would be very cool if you'll find a way. I don't want any workaround and want to understand how it coud be made.

    Thank you for having a look at this!

  17. #17
    Lively Member
    Join Date
    Mar 2012
    Posts
    113

    Re: Star Rating Control

    Thanks Dear it helped me too

    God Bless..!!! Keep sharing

    Best Regards,

    Sam

  18. #18
    New Member
    Join Date
    Mar 2013
    Posts
    2

    Re: Star Rating Control

    Hi Stepdragon,

    I have been looking for this since some time now. Looks awesome and just what i want. Thank you!!

    I am trying to use your code in excel vba [my project restricts me to excel vba only ], but unfortunately it isnt working on vba. Is there something that i need to take care of before i can use it on vba?

    I could use some help.

    Thanks in advance.

  19. #19

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by sujeethkv View Post
    Hi Stepdragon,

    I have been looking for this since some time now. Looks awesome and just what i want. Thank you!!

    I am trying to use your code in excel vba [my project restricts me to excel vba only ], but unfortunately it isnt working on vba. Is there something that i need to take care of before i can use it on vba?

    I could use some help.

    Thanks in advance.
    I foresee two problems with attempting to use my code with VBA. The first of which is that as per VBForums Guidelines we cannot distribute complied code, and therefore you will need to use an appropriate version of VB.Net to build my code before you can use it in your own app. When using VB.Net this can all be done together while compiling, however VBA doesn't compile to executable code, and therefore cannot create the control to begin with.

    The second problem I can think of is that this is a VB.Net control. I haven't used VBA in a while but isn't it based off of classic VB? rather than .Net? This could just be my own misunderstanding because I haven't used VBA in years. But if it isn't based upon VB.Net it may not even be able to load the control in the first place.


    tl;dr: I recommend obtaining a version of VB.Net (express version is a free downloaded from Microsoft). Even if you cannot use or even install it on your target machine, you can use another machine to compile the code and create a .dll file. From there you can take that file to your target machine and import it into VBA.

    If you have any issues or compatibility problems from here, it would be best to post a question into the appropriate forum where more people will be able to help.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  20. #20
    New Member
    Join Date
    Mar 2013
    Posts
    2

    Re: Star Rating Control

    5_star_ratings.zip

    Thanks stepdragon

    was not able to do with the draw api on vba. had to go for the image choice only. Thanks for the help and the code .

  21. #21
    New Member
    Join Date
    Jul 2013
    Posts
    2

    Re: Star Rating Control

    Quote Originally Posted by geniyin View Post
    so v nid to create a database to store each rating for each object right? so to save and get its average from database each time d project is compile?
    Here is another example of using your Star rating Control using A SELECT CASE


    <code>Private Sub StarRate1_ValueChanged(Value As Integer, UserChanged As Boolean) Handles StarRate1.ValueChanged
    Select Case Value
    Case 0
    TextBox1.Text = ""
    Case 1
    TextBox1.Text = "you choose 1 star"
    Case 2
    TextBox1.Text = "you choose 2 star"
    Case 3
    TextBox1.Text = "you choose 3 star"
    Case 4
    TextBox1.Text = "you choose 4 star"
    Case 5
    TextBox1.Text = "you choose 5 star"
    End Select
    End Sub</code>

  22. #22
    New Member
    Join Date
    Jul 2013
    Posts
    2

    Re: Star Rating Control

    whoops wrong quote on my last post

    Does not Code boxes work on this forum?

  23. #23

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Use brackets instead of Tags:

    [code] dim content as string [/code]
    makes:
    Code:
     dim content as string
    <code> dim content as string </code>
    makes:
    <code> dim content as string </code>

    [highlight=vb.net] dim content as string [/highlight]
    makes:
    vb.net Code:
    1. dim content as string

    For more, check out 'how to use code tags' in my sig.


    as a side note, I'd love to see some screenshots of how you're using my control. I'm so happy that two years later I can still find it on the front page of the codebank!
    Last edited by stepdragon; Aug 10th, 2013 at 11:56 PM.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  24. #24
    Registered User
    Join Date
    Sep 2013
    Posts
    1

    Re: Star Rating Control

    Using your control in my video management system. It looks great!

  25. #25
    New Member
    Join Date
    Aug 2014
    Posts
    1

    Re: Star Rating Control

    Hi, Just letting you know that I'm using your control! Thanx!!

  26. #26
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Star Rating Control

    I saw this and thought it looked interesting so I downloaded it even though I don't currently have a use for it... Just a comment: for making it more consistent with other controls, I'd change your "DisplayOnly" property to "Enabled" instead.

  27. #27

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by Pyth007 View Post
    I saw this and thought it looked interesting so I downloaded it even though I don't currently have a use for it... Just a comment: for making it more consistent with other controls, I'd change your "DisplayOnly" property to "Enabled" instead.
    I like the idea of including an enabled property, however in terms of keeping consistent with other controls, I would think that an enabled property would gray out the entire control. regardless of if stars were selected, not just disable user input. Think of a textbox, it grays out. I may experiment and see what works best and post an update.

    Remember, you're completely welcome to edit the code and post your own version in the comments. I know this thread isn't that long, but I'll try to put a link to your version in the top post so it can be found easier. If you choose to do so.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  28. #28
    New Member
    Join Date
    Apr 2015
    Posts
    3

    Re: Star Rating Control

    Hey, how do i send you a pm? I could really use your help on coding if you would be so kind. Thanks.

  29. #29

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by rhyzw View Post
    Hey, how do i send you a pm? I could really use your help on coding if you would be so kind. Thanks.
    If you're having trouble with a program. Please post in the appropriate forum. If you have a question, odds are someone else does too. By posting in the forum on a well titled thread, you will help others who have similar questions find their answers as well.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  30. #30
    Member
    Join Date
    Sep 2015
    Posts
    46

    Re: Star Rating Control

    Hey, ummm, I wanna use your control for my first project.... But I don't know even know how to open it..... I'm doing my project on vb6 btw.....

  31. #31

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    The control was coded for .Net, and while there is nothing .Net specific in the code (as far as I recall) it would need to be reworked for earlier versions of VB, which I do not intend to do anytime soon.

    Perhaps someone in the VB6 forum can help you convert it. Your welcome to do so.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  32. #32
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Star Rating Control

    I've noticed a problem with this. If I select a value, then I cannot go back to selecting 0 stars. I can go to a minimum of 1, but not 0.

  33. #33

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by Legjendat View Post
    I've noticed a problem with this. If I select a value, then I cannot go back to selecting 0 stars. I can go to a minimum of 1, but not 0.
    It's been a while since I looked at this code. But if I remember correctly, it will reset to zero of you click the currently selected star a second time.

    You are welcome to add a context menu to it with a reset option if you think that will be more user friendly for your needs.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  34. #34
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Star Rating Control

    Quote Originally Posted by stepdragon View Post
    It's been a while since I looked at this code. But if I remember correctly, it will reset to zero of you click the currently selected star a second time.

    You are welcome to add a context menu to it with a reset option if you think that will be more user friendly for your needs.
    Oh wow, hadn't noticed that if you click the selected value again it will reset to 0, that's more than enough for my needs, thanks for the reply, this control will be very helpful for my app once I'm done with it, and again thanks for the reply, I noticed u hadn't logged in since February

  35. #35

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Star Rating Control

    Quote Originally Posted by Legjendat View Post
    Oh wow, hadn't noticed that if you click the selected value again it will reset to 0, that's more than enough for my needs, thanks for the reply, this control will be very helpful for my app once I'm done with it, and again thanks for the reply, I noticed u hadn't logged in since February
    I subscribe to all my threads

    Even 5 years later

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  36. #36
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Star Rating Control

    An honorable choice
    Good job on the control btw, nice and simple, and it has all the options one needs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width