Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Directives
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Drawing.Imaging;
- using System.Linq;
- #endregion
- #region Browse
- /* Copyright & Contact
- * --------------------------------------------------------------------------------<
- * Tool Name : ProgressBar *
- * From Project : Creator Eye *
- * Project Lang : C# *
- * 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 : Dark Theme *
- * Style : Indicator *
- *>--------------------------------------------------------------------------------<
- */
- /* Features
- * ------------------------
- * Custom Properties:
- * Create Indicator Style.
- * add the range specified by minimum and maximum value.
- * Using Relative Value Style
- */
- /* history
- * ------------------------
- * 1.0 (20 Feb 2018):
- * In my Source Code Get Circular progress-bar Like Gmail Style with Great Effect.
- * So, in this case,you can use this controller as Circular Progress Bar with input Or edit value, and maximum value.
- *
- */
- #endregion
- #region Progress Indicator
- class CeIndicatorProgressBar : Control
- {
- #region Variables
- private readonly SolidBrush BaseColor = new SolidBrush(Color.FromArgb(76, 76, 76));
- private readonly SolidBrush AnimationColor = new SolidBrush(Color.Gray);
- private readonly Timer AnimationSpeed = new Timer();
- private PointF[] FloatPoint;
- private BufferedGraphics BuffGraphics;
- private int IndicatorIndex;
- private readonly BufferedGraphicsContext GraphicsContext = BufferedGraphicsManager.Current;
- #endregion
- #region Custom Properties
- public Color P_BaseColor
- {
- get { return BaseColor.Color; }
- set { BaseColor.Color = value; }
- }
- public Color P_AnimationColor
- {
- get { return AnimationColor.Color; }
- set { AnimationColor.Color = value; }
- }
- public int P_AnimationSpeed
- {
- get { return AnimationSpeed.Interval; }
- set { AnimationSpeed.Interval = value; }
- }
- #endregion
- #region EventArgs
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- SetStandardSize();
- UpdateGraphics();
- SetPoints();
- }
- protected override void OnEnabledChanged(EventArgs e)
- {
- base.OnEnabledChanged(e);
- AnimationSpeed.Enabled = this.Enabled;
- }
- protected override void OnHandleCreated(EventArgs e)
- {
- base.OnHandleCreated(e);
- AnimationSpeed.Tick += AnimationSpeed_Tick;
- AnimationSpeed.Start();
- }
- private void AnimationSpeed_Tick(object sender, EventArgs e)
- {
- if (IndicatorIndex.Equals(0))
- {
- IndicatorIndex = FloatPoint.Length - 1;
- }
- else
- {
- IndicatorIndex -= 1;
- }
- this.Invalidate(false);
- }
- #endregion
- public CeIndicatorProgressBar()
- {
- this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
- Size = new Size(80, 80);
- Text = string.Empty;
- MinimumSize = new Size(80, 80);
- SetPoints();
- AnimationSpeed.Interval = 100;
- }
- private void SetStandardSize()
- {
- int _Size = Math.Max(Width, Height);
- Size = new Size(_Size, _Size);
- }
- private void SetPoints()
- {
- Stack<PointF> stack = new Stack<PointF>();
- PointF startingFloatPoint = new PointF(((float)this.Width) / 2f, ((float)this.Height) / 2f);
- for (float i = 0f; i < 360f; i += 45f)
- {
- this.SetValue(startingFloatPoint, (int)Math.Round((double)((((double)this.Width) / 2.0) - 15.0)), (double)i);
- PointF endPoint = this.EndPoint;
- endPoint = new PointF(endPoint.X - 7.5f, endPoint.Y - 7.5f);
- stack.Push(endPoint);
- }
- this.FloatPoint = stack.ToArray();
- }
- private void UpdateGraphics()
- {
- if ((this.Width > 0) && (this.Height > 0))
- {
- Size size2 = new Size(this.Width + 1, this.Height + 1);
- this.GraphicsContext.MaximumBuffer = size2;
- this.BuffGraphics = this.GraphicsContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
- this.BuffGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- this.BuffGraphics.Graphics.Clear(this.BackColor);
- int num2 = this.FloatPoint.Length - 1;
- for (int i = 0; i <= num2; i++)
- {
- if (this.IndicatorIndex == i)
- {
- this.BuffGraphics.Graphics.FillEllipse(this.AnimationColor, this.FloatPoint[i].X, this.FloatPoint[i].Y, 15f, 15f);
- }
- else
- {
- this.BuffGraphics.Graphics.FillEllipse(this.BaseColor, this.FloatPoint[i].X, this.FloatPoint[i].Y, 15f, 15f);
- }
- }
- this.BuffGraphics.Render(e.Graphics);
- }
- private double Rise;
- private double Run;
- private PointF _StartingFloatPoint;
- private X AssignValues<X>(ref X Run, X Length)
- {
- Run = Length;
- return Length;
- }
- private void SetValue(PointF StartingFloatPoint, int Length, double Angle)
- {
- double CircleRadian = Math.PI * Angle / 180.0;
- _StartingFloatPoint = StartingFloatPoint;
- Rise = AssignValues(ref Run, Length);
- Rise = Math.Sin(CircleRadian) * Rise;
- Run = Math.Cos(CircleRadian) * Run;
- }
- private PointF EndPoint
- {
- get
- {
- float LocationX = Convert.ToSingle(_StartingFloatPoint.Y + Rise);
- float LocationY = Convert.ToSingle(_StartingFloatPoint.X + Run);
- return new PointF(LocationY, LocationX);
- }
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement