Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / C#

Star Rating Control With No Messy GDI Bits!

Rate me:
Please Sign up or sign in to vote.
3.27/5 (15 votes)
2 Feb 2011CPOL7 min read 71.4K   900   41  
A non GDI version of a star rating control
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Intel.GSTag.WinControls.StarRating;

namespace StarRatingTester
{
	public class Form1 : Form
	{
		private System.Windows.Forms.Panel panel1;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl5;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl1;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl2;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl3;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl4;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl6;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl7;
		private Intel.GSTag.WinControls.StarRating.StarRatingControl starRatingControl8;
		private Container components = null;

		public Form1()
		{
			InitializeComponent();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.starRatingControl5 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl1 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl2 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl3 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl4 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl6 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl7 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.starRatingControl8 = new Intel.GSTag.WinControls.StarRating.StarRatingControl();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.AutoScroll = true;
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel1.Location = new System.Drawing.Point(8, 8);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(112, 200);
			this.panel1.TabIndex = 3;
			// 
			// starRatingControl5
			// 
			this.starRatingControl5.CurrentStarValue = 0;
			this.starRatingControl5.Location = new System.Drawing.Point(128, 8);
			this.starRatingControl5.Name = "starRatingControl5";
			this.starRatingControl5.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl5.StarCount = 5;
			this.starRatingControl5.TabIndex = 4;
			// 
			// starRatingControl1
			// 
			this.starRatingControl1.CurrentStarValue = 0;
			this.starRatingControl1.Location = new System.Drawing.Point(128, 104);
			this.starRatingControl1.Name = "starRatingControl1";
			this.starRatingControl1.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl1.StarCount = 5;
			this.starRatingControl1.TabIndex = 5;
			// 
			// starRatingControl2
			// 
			this.starRatingControl2.CurrentStarValue = 0;
			this.starRatingControl2.Location = new System.Drawing.Point(128, 80);
			this.starRatingControl2.Name = "starRatingControl2";
			this.starRatingControl2.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl2.StarCount = 5;
			this.starRatingControl2.TabIndex = 6;
			// 
			// starRatingControl3
			// 
			this.starRatingControl3.CurrentStarValue = 0;
			this.starRatingControl3.Location = new System.Drawing.Point(128, 56);
			this.starRatingControl3.Name = "starRatingControl3";
			this.starRatingControl3.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl3.StarCount = 5;
			this.starRatingControl3.TabIndex = 7;
			// 
			// starRatingControl4
			// 
			this.starRatingControl4.CurrentStarValue = 0;
			this.starRatingControl4.Location = new System.Drawing.Point(128, 32);
			this.starRatingControl4.Name = "starRatingControl4";
			this.starRatingControl4.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl4.StarCount = 5;
			this.starRatingControl4.TabIndex = 8;
			// 
			// starRatingControl6
			// 
			this.starRatingControl6.CurrentStarValue = 0;
			this.starRatingControl6.Location = new System.Drawing.Point(128, 144);
			this.starRatingControl6.Name = "starRatingControl6";
			this.starRatingControl6.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl6.StarCount = 5;
			this.starRatingControl6.TabIndex = 9;
			// 
			// starRatingControl7
			// 
			this.starRatingControl7.CurrentStarValue = 0;
			this.starRatingControl7.Location = new System.Drawing.Point(128, 168);
			this.starRatingControl7.Name = "starRatingControl7";
			this.starRatingControl7.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl7.StarCount = 5;
			this.starRatingControl7.TabIndex = 10;
			// 
			// starRatingControl8
			// 
			this.starRatingControl8.CurrentStarValue = 0;
			this.starRatingControl8.Location = new System.Drawing.Point(128, 192);
			this.starRatingControl8.Name = "starRatingControl8";
			this.starRatingControl8.Size = new System.Drawing.Size(75, 14);
			this.starRatingControl8.StarCount = 5;
			this.starRatingControl8.TabIndex = 11;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(304, 214);
			this.Controls.Add(this.starRatingControl8);
			this.Controls.Add(this.starRatingControl7);
			this.Controls.Add(this.starRatingControl6);
			this.Controls.Add(this.starRatingControl4);
			this.Controls.Add(this.starRatingControl3);
			this.Controls.Add(this.starRatingControl2);
			this.Controls.Add(this.starRatingControl1);
			this.Controls.Add(this.starRatingControl5);
			this.Controls.Add(this.panel1);
			this.Name = "Form1";
			this.Text = "5 Star tester";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}

		#endregion

		[STAThread]
		private static void Main()
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			int y = 0;
			for(int x=0;x<16;x++)
			{
				StarRatingControl value = new StarRatingControl();
				value.Top = y;
				panel1.Controls.Add(value);
				y += value.Height;
			}
			Bitmap bitmap = new Bitmap(this.GetType(),"StarOnBlue.bmp");
			Bitmap[] images = new Bitmap[] {bitmap};

			starRatingControl1.CurrentStarValue = 1;
			starRatingControl1.OnImages = images;

			starRatingControl2.OnImages = images;
			starRatingControl2.CurrentStarValue = 2;

			starRatingControl3.OnImages = images;
			starRatingControl3.CurrentStarValue = 3;

			starRatingControl4.OnImages = images;
			starRatingControl4.CurrentStarValue = 4;

			starRatingControl5.OnImages = images;
			starRatingControl5.CurrentStarValue = 5;

			starRatingControl6.StarCount = 6;
			starRatingControl6.OnImages = images;
			starRatingControl6.CurrentStarValue = 3;

			starRatingControl7.StarCount = 8;
			starRatingControl7.OnImages = images;
			starRatingControl7.CurrentStarValue = 4;

			starRatingControl8.StarCount = 10;
			starRatingControl8.OnImages = images;
			starRatingControl8.CurrentStarValue = 5;

		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Web Developer
United States United States
I've been a software developer for the last 15 years. Everthing from FOCUS on the Vax and Mainframe, through Artifical intelligence programing with level 5 object to the .net framework today.

Comments and Discussions