Advertisement
Yassine_Abbani

Lolipop [Button], [Custom Color]

May 24th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.00 KB | None | 0 0
  1. #region Directives
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Drawing.Text;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. #endregion
  14. #region Browse
  15. /* Copyright & Contact
  16. * --------------------------------------------------------------------------------<
  17. * Tool Name    : Switch Button                                                    *
  18. * From Project : Creators Eye                                                      *
  19. * Project Lang : C#                                                               *
  20. * Creator      : Yassine Abbani                                                   *
  21. * Facebook     : https://www.facebook.com/YassineAbbani.user                      *
  22. * Pastebin     : https://pastebin.com/u/Yassine_Abbani                            *
  23. * Youtube      : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw         *
  24. * Version      : 1.0 Beta                                                         *
  25. * Color        : Multi-Color                                                      *
  26. * Style        : Lolipop                                                          *
  27. *>--------------------------------------------------------------------------------<
  28. */
  29. /* Features
  30. * ------------------------
  31.  * Creators Eye Lolipop Switch is a custom toggle control similar to Bunifu switch. The difference is that it has a sliding circle inside the component that performs the switching. It can be themed with color customization to fit the look and feel of your other controls.
  32.  * Creators Eye Lolipop Switch can be added at design time using drag and drop and at runtime
  33.  * Possible customizations:
  34.  * Ability to change on and off colors*/
  35. /*  history
  36. * ------------------------
  37.  * 1.0 (24 Feb 2018):
  38.  * Custom Properties
  39.  * Set the color of Ce Lolipop switch when ON using OnColor property
  40.  * Set the color of Ce Lolipop switch when on OFF status using OffColor property
  41. */
  42. #endregion
  43. #region Browse
  44. /* Copyright & Contact
  45. * --------------------------------------------------------------------------------<
  46. * Tool Name    : Card                                                             *
  47. * From Project : Creator Eye                                                      *
  48. * Project Lang : C#                                                               *
  49. * Creator      : Yassine Abbani                                                   *
  50. * Facebook     : https://www.facebook.com/YassineAbbani.user                      *
  51. * Pastebin     : https://pastebin.com/u/Yassine_Abbani                            *
  52. * Youtube      : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw         *
  53. * Version      : 1.0 Beta                                                         *
  54. * Color        : Dark Theme                                                       *
  55. * Style        : Smal                                                             *
  56. *>--------------------------------------------------------------------------------<
  57. */
  58. /* Features
  59. * ------------------------
  60.  * We Was Converting rbg color to Html color
  61.  * Creators Eye Cards is a custom control that arranges your info or controls inside a beautiful panel. It makes your dashboard presentation more organized and aligned.
  62. */
  63. /*  history
  64. * ------------------------
  65. * 1.0 (24 Feb 2018):
  66. *
  67. * Custom Properties
  68.  * Ability to add image to the left side of the card using property
  69.  * Ability to change the color of the card image using Color property
  70. */
  71. #endregion
  72. #region Andriod Switch
  73. public class Ce_AndriodSwitch : CheckBox
  74. {
  75.     #region Variables
  76.  
  77.     Timer AnimationTimer = new Timer { Interval = 1 };
  78.     GraphicsPath RoundedRectangle;
  79.  
  80.     string EllipseBG = "#508ef5";
  81.     string EllipseBorder = "#3b73d1";
  82.  
  83.     Color EllipseBackColor;
  84.     Color EllipseBorderBackColor;
  85.  
  86.     Color EnabledUnCheckedColor = ColorTranslator.FromHtml("#bcbfc4");
  87.     Color EnabledUnCheckedEllipseBorderColor = ColorTranslator.FromHtml("#a9acb0");
  88.  
  89.     Color DisabledEllipseBackColor = ColorTranslator.FromHtml("#c3c4c6");
  90.     Color DisabledEllipseBorderBackColor = ColorTranslator.FromHtml("#90949a");
  91.  
  92.     int PointAnimationNum = 4;
  93.  
  94.     #endregion
  95.     #region  Properties
  96.  
  97.     [Category("Appearance")]
  98.     public string EllipseColor
  99.     {
  100.         get { return EllipseBG; }
  101.         set
  102.         {
  103.             EllipseBG = value;
  104.             Invalidate();
  105.         }
  106.     }
  107.     [Category("Appearance")]
  108.     public string EllipseBorderColor
  109.     {
  110.         get { return EllipseBorder; }
  111.         set
  112.         {
  113.             EllipseBorder = value;
  114.             Invalidate();
  115.         }
  116.     }
  117.  
  118.     #endregion
  119.     #region Events
  120.  
  121.     protected override void OnHandleCreated(EventArgs e)
  122.     {
  123.         base.OnHandleCreated(e);
  124.         AnimationTimer.Start();
  125.     }
  126.  
  127.     protected override void OnResize(EventArgs e)
  128.     {
  129.         Height = 19; Width = 47;
  130.  
  131.         RoundedRectangle = new GraphicsPath();
  132.         int radius = 10;
  133.  
  134.         RoundedRectangle.AddArc(11, 4, radius - 1, radius, 180, 90);
  135.         RoundedRectangle.AddArc(Width - 21, 4, radius - 1, radius, -90, 90);
  136.         RoundedRectangle.AddArc(Width - 21, Height - 15, radius - 1, radius, 0, 90);
  137.         RoundedRectangle.AddArc(11, Height - 15, radius - 1, radius, 90, 90);
  138.  
  139.         RoundedRectangle.CloseAllFigures();
  140.         Invalidate();
  141.     }
  142.  
  143.     #endregion
  144.     public Ce_AndriodSwitch()
  145.     {
  146.         Height = 19; Width = 47; DoubleBuffered = true;
  147.         AnimationTimer.Tick += new EventHandler(AnimationTick);
  148.     }
  149.  
  150.     protected override void OnPaint(PaintEventArgs pevent)
  151.     {
  152.         var G = pevent.Graphics;
  153.         G.SmoothingMode = SmoothingMode.AntiAlias;
  154.         G.Clear(Parent.BackColor);
  155.  
  156.         EllipseBackColor = ColorTranslator.FromHtml(EllipseBG);
  157.         EllipseBorderBackColor = ColorTranslator.FromHtml(EllipseBorder);
  158.  
  159.         G.FillPath(new SolidBrush(Color.FromArgb(115, Enabled ? Checked ? EllipseBackColor : EnabledUnCheckedColor : EnabledUnCheckedColor)), RoundedRectangle);
  160.         G.DrawPath(new Pen(Color.FromArgb(50, Enabled ? Checked ? EllipseBackColor : EnabledUnCheckedColor : EnabledUnCheckedColor)), RoundedRectangle);
  161.  
  162.         G.FillEllipse(new SolidBrush(Enabled ? Checked ? EllipseBackColor : Color.White : DisabledEllipseBackColor), PointAnimationNum, 0, 18, 18);
  163.         G.DrawEllipse(new Pen(Enabled ? Checked ? EllipseBorderBackColor : EnabledUnCheckedEllipseBorderColor : DisabledEllipseBorderBackColor), PointAnimationNum, 0, 18, 18);
  164.     }
  165.  
  166.     void AnimationTick(object sender, EventArgs e)
  167.     {
  168.         if (Checked)
  169.         {
  170.             if (PointAnimationNum < 24)
  171.             {
  172.                 PointAnimationNum += 1;
  173.                 this.Invalidate();
  174.             }
  175.         }
  176.         else if (PointAnimationNum > 4)
  177.         {
  178.             PointAnimationNum -= 1;
  179.             this.Invalidate();
  180.         }
  181.     }
  182. }
  183. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement