Click here to Skip to main content
15,883,705 members
Articles / Desktop Programming / Windows Forms
Article

ShaperRater - A Rating Control

Rate me:
Please Sign up or sign in to vote.
4.88/5 (33 votes)
2 Jun 2008CPOL2 min read 53.2K   2.3K   62   11
A custom control to graphically select a ratings value.

Image 1

Introduction

The ShaperRater is a simple bindable ratings control to graphically show a rating value. We've all used something similar before in rating music or movies.

Here is a list of its features:

  1. If you don't like stars, this control has other shapes to choose from.
  2. A label is available to display different text for each value.
  3. Separate border and fill colors for each state: empty, filled, or being hovered over.
  4. Value numbers (all or just selected value) can be displayed with the shape.

Background

I was writing a DVD movie database program, and wanted to have a rating control like what I have seen elsewhere. I started out using little images, and although it did work, I wanted more versatility, so I started over and began drawing the shapes directly. This made design-time better, and made the control more dynamic.

Control Properties

Here is a list of the primary properties:

  • CurrentRating
  • This is the bindable ratings value.

  • MaxRating
  • How many shapes to draw.

  • Shape
  • Star, Circle, Square, Triangle, Heart, and Diamond.

  • RadiusOuter
  • Radius size for shape.

  • RadiusInner
  • The second radius of the Star shape.

  • ShapeGap
  • Set gap between each shape.

  • ShapeBorderEmptyColor, ShapeBorderFilledColor, ShapeBorderHoverColor
  • Color of the border for each state.

  • ShapeColorEmpty, ShapeColorFill, ShapeColorHover
  • Color to fill the shape for each state.

  • HighlightRateFill, HighlightRateHover
  • Changes the behavior of the fill and/or hover to highlight all the shapes or just the value shape.

  • ShapeNumberShow
  • Whether to show the number: None, All, or RateOnly.

  • ShapeNumberColor, ShapeNumberFont
  • Format the number shown.

  • ShapeNumberIndent
  • Tweak the position of the number.

  • LabelAlignment, LabelIndent, LabelShow
  • Label formatting options.

  • LabelText
  • Base text to display and 0 value text.

  • LabelTextItems
  • Text to display for each selected rating.

  • LabelFormatString
  • String.Format where {0} = rate being hovered over and {1} = the MaxRating.

  • LabelTypeHover, LabelTypeText
  • What type of text to display while hovering and after selection.

Using the Code

Once you get the ShaperRater designed the way you want, there isn't really any code. Just get the CurrentRating and use it the way you want:

VB
Private Sub Rater1_CurrentRatingChanged(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Rater1.CurrentRatingChanged

    MessageBox.Show(Rater1.CurrentRating)
End Sub

Using the Control

  • Left click the control to select the CurrentRating.
  • Right click to reset the CurrentRating back to 0 during runtime.

History

  • Version 1.0 - March 2008.

License

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


Written By
Software Developer
United States United States
I first got hooked on programing with the TI994A. After it finally lost all support I reluctantly moved to the Apple IIe. Thank You BeagleBros for getting me through. I wrote programs for my Scuba buisness during this time. Currently I am a Database manager and software developer. I started with VBA and VB6 and now having fun with VB.NET/WPF/C#...

Comments and Discussions

 
Questionrating on asp.net Pin
Member 1459325916-May-21 1:58
Member 1459325916-May-21 1:58 
GeneralMy Rating of 5 Pin
chrisf865727-Feb-15 22:17
chrisf865727-Feb-15 22:17 
QuestionThanks for this. Great stuff Pin
Przemyslaw Koszka30-Jan-14 0:42
Przemyslaw Koszka30-Jan-14 0:42 
Questiontanx Pin
ali yeganeh17-Jan-13 22:59
ali yeganeh17-Jan-13 22:59 
GeneralGood stuff! [modified] Pin
Ton_B17-Sep-09 10:28
Ton_B17-Sep-09 10:28 
GeneralRe: Good stuff! Pin
SSDiver211218-Sep-09 8:00
SSDiver211218-Sep-09 8:00 
Thanks Ton_B,

Had a lot of good times on that TI. A friend of mine from high school still has his and it still works.

As for this control: You could even paint a box or somthing to visually click on to clear the value.

Just to let you know though, it already had the zero out feature by right clicking.

Using the Control
•Left click the control to select the CurrentRating.
•Right click to reset the CurrentRating back to 0 during runtime.

Thanks again,
GeneralRe: Good stuff! Pin
Ton_B18-Sep-09 23:31
Ton_B18-Sep-09 23:31 
GeneralReally good! Pin
z00z011-Jun-08 1:01
z00z011-Jun-08 1:01 
GeneralNice one Pin
Ahmed IG2-Jun-08 7:28
Ahmed IG2-Jun-08 7:28 
GeneralRe: Nice one Pin
Sneeha30-Aug-08 18:25
Sneeha30-Aug-08 18:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.