Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Directives
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- #endregion
- #region Copyright & Contact
- //>-------------------------------------------------------------------------------<
- // Tool Name : Rating Strip *
- // From Project : Creator Eye *
- // Creator : Yassine Abbani *
- // Facebook : https://www.facebook.com/YassineAbbani.user *
- // Pastebin : https://pastebin.com/u/Yassine_Abbani *
- // Youtube : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw *
- // Version : 1.0 Beta *
- // Color : Nul *
- // Style : Costume *
- //>-------------------------------------------------------------------------------<
- /*
- * Properties
- * Add Image as rated,Unrated control
- *
- */
- #endregion
- #region Costume Rating Strip
- public class Ce_CostumeRating : UserControl
- {
- #region Variables
- private Size _ImageSize;
- private Image _ImageRated;
- private Image _ImageUnrated;
- private int _Stars = 0;
- private int _MaximumStars = 5;
- private int TempStar = -1;
- #endregion
- #region Properties
- protected Size ImageSize
- {
- get
- {
- return _ImageSize;
- }
- }
- public int Stars
- {
- get
- {
- return this._Stars;
- }
- set
- {
- if (value > _MaximumStars)
- {
- MessageBox.Show("Value can\'t be higher than the maximum number of stars!");
- }
- this._Stars = value;
- this.Invalidate();
- }
- }
- public int MaximumStars
- {
- get
- {
- return this._MaximumStars;
- }
- set
- {
- this._MaximumStars = value;
- }
- }
- public Image ImageRated
- {
- get
- {
- return _ImageRated;
- }
- set
- {
- if (value == null)
- {
- _ImageSize = Size.Empty;
- }
- else
- {
- _ImageSize = value.Size;
- }
- _ImageRated = value;
- Invalidate();
- }
- }
- public Image ImageUnrated
- {
- get
- {
- return _ImageUnrated;
- }
- set
- {
- if (value == null)
- {
- _ImageSize = Size.Empty;
- }
- else
- {
- _ImageSize = value.Size;
- }
- _ImageUnrated = value;
- Invalidate();
- }
- }
- #endregion
- #region EventArgs
- protected override void OnMouseMove(MouseEventArgs e)
- {
- base.OnMouseMove(e);
- double StarLoc = (e.X + _ImageRated.Width - 5) / _ImageRated.Width;
- int HoverStar = Convert.ToInt32(Math.Floor(StarLoc));
- if (!HoverStar.Equals(TempStar))
- {
- TempStar = HoverStar;
- this.Invalidate();
- }
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- TempStar = -1;
- this.Invalidate();
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- double StarLoc = (e.X + _ImageRated.Width - 5) / _ImageRated.Width;
- int StarToAdd = Convert.ToInt32(Math.Floor(StarLoc));
- if (!StarToAdd.Equals(_Stars))
- {
- _Stars = StarToAdd;
- if (_Stars > _MaximumStars)
- {
- _Stars = _MaximumStars;
- }
- this.Invalidate();
- }
- }
- #endregion
- #region
- public Ce_CostumeRating()
- {
- Size = new Size(82, 17);
- BackColor = Color.Transparent;
- DoubleBuffered = true;
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- Graphics G = e.Graphics;
- if (_ImageRated == null || _ImageUnrated == null)
- {
- return;
- }
- for (int i = 0; i <= _MaximumStars - 1; i++)
- {
- if (i < (TempStar == -1 ? _Stars : TempStar))
- {
- G.DrawImage(_ImageRated, _ImageRated.Width * i, 0, ImageSize.Width, ImageSize.Height);
- }
- else
- {
- G.DrawImage(_ImageUnrated, _ImageRated.Width * i, 0, ImageSize.Width, ImageSize.Height);
- }
- }
- }
- #endregion
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement