Click here to Skip to main content
Click here to Skip to main content

ShaperRater - A Rating Control

, 2 Jun 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

  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:

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)

Share

About the Author

SSDiver2112
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

Comments and Discussions

 
QuestionThanks for this. Great stuff PinmemberPrzemyslaw Koszka30-Jan-14 1:42 
Questiontanx Pinmemberali yeganeh17-Jan-13 23:59 
GeneralGood stuff! [modified] PinmemberTon_B17-Sep-09 11:28 
GeneralRe: Good stuff! PinmemberSSDiver211218-Sep-09 9:00 
GeneralRe: Good stuff! PinmemberTon_B19-Sep-09 0:31 
GeneralMessage Automatically Removed PinmemberDotNetGuts4-Dec-08 17:59 
GeneralReally good! Pinmemberz00z011-Jun-08 2:01 
GeneralNice one PinmemberAhmed IG2-Jun-08 8:28 
GeneralRe: Nice one PinmemberSneeha30-Aug-08 19:25 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 2 Jun 2008
Article Copyright 2008 by SSDiver2112
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid