ShaperRater - A Rating Control






4.88/5 (31 votes)
A custom control to graphically select a ratings value.
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:
- If you don't like stars, this control has other shapes to choose from.
- A label is available to display different text for each value.
- Separate border and fill colors for each state: empty, filled, or being hovered over.
- 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
MaxRating
Shape
RadiusOuter
RadiusInner
ShapeGap
ShapeBorderEmptyColor
,ShapeBorderFilledColor
,ShapeBorderHoverColor
ShapeColorEmpty
,ShapeColorFill
,ShapeColorHover
HighlightRateFill
,HighlightRateHover
ShapeNumberShow
ShapeNumberColor
,ShapeNumberFont
ShapeNumberIndent
LabelAlignment
,LabelIndent
,LabelShow
LabelText
LabelTextItems
LabelFormatString
LabelTypeHover
,LabelTypeText
This is the bindable ratings value.
How many shapes to draw.
Star
, Circle
, Square
, Triangle
, Heart
, and Diamond
.
Radius size for shape.
The second radius of the Star
shape.
Set gap between each shape.
Color of the border for each state.
Color to fill the shape for each state.
Changes the behavior of the fill and/or hover to highlight all the shapes or just the value shape.
Whether to show the number: None
, All
, or RateOnly
.
Format the number shown.
Tweak the position of the number.
Label formatting options.
Base text to display and 0 value text.
Text to display for each selected rating.
String.Format
where {0} = rate being hovered over and {1} = the MaxRating
.
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:
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.