Advertisement
Yassine_Abbani

Card [Dashboard],[Custom Control]

May 24th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.56 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    : Card                                                             *
  18. * From Project : Creator 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        : Dark Theme                                                       *
  26. * Style        : Smal                                                             *
  27. *>--------------------------------------------------------------------------------<
  28. */
  29. /* Features
  30. * ------------------------
  31.  * We Was Converting rbg color to Html color
  32.  * 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.
  33. */
  34. /*  history
  35. * ------------------------
  36. * 1.0 (24 Feb 2018):
  37. *
  38. * Custom Properties
  39.  * Ability to add image to the left side of the card using property
  40.  * Ability to change the color of the card image using Color property
  41. */
  42. #endregion
  43. #region Card
  44. public class Ce_Card : Control
  45. {
  46.  
  47.     #region Variables
  48.  
  49.     FontManager font = new FontManager();
  50.     Image image;
  51.  
  52.     string information = "Type here any thing you want to type :) ";
  53.     string Titelcolor = "#00AEDB";
  54.     string thumbnailcolor = "#00AEDB";
  55.  
  56.     Color BgColor;
  57.     Color StringColor;
  58.     Color ThumbnailBGColor;
  59.     Color BorderColor = ColorTranslator.FromHtml("#00AEDB");
  60.  
  61.     #endregion
  62.     #region Properties
  63.  
  64.     [Category("Appearance")]
  65.     public Image Image
  66.     {
  67.         get
  68.         {
  69.             return image;
  70.         }
  71.         set
  72.         {
  73.             image = value;
  74.             Invalidate();
  75.         }
  76.     }
  77.  
  78.     [Category("Appearance")]
  79.     public string ThumbnailColor
  80.     {
  81.         get { return thumbnailcolor; }
  82.         set
  83.         {
  84.             thumbnailcolor = value;
  85.             Invalidate();
  86.         }
  87.     }
  88.  
  89.     [Category("Appearance")]
  90.     public string TitelColor
  91.     {
  92.         get { return Titelcolor; }
  93.         set
  94.         {
  95.             Titelcolor = value;
  96.             Invalidate();
  97.         }
  98.     }
  99.     [Category("Appearance")]
  100.     public string Description
  101.     {
  102.         get { return information; }
  103.         set
  104.         {
  105.             information = value;
  106.             Invalidate();
  107.         }
  108.     }
  109.  
  110.     [Browsable(false)]
  111.     public Font Font
  112.     {
  113.         get { return base.Font; }
  114.         set { base.Font = value; }
  115.     }
  116.  
  117.     [Browsable(false)]
  118.     public Color ForeColor
  119.     {
  120.         get { return base.ForeColor; }
  121.         set { base.ForeColor = value; }
  122.     }
  123.  
  124.     #endregion
  125.     #region Events
  126.  
  127.     protected override void OnMouseEnter(EventArgs e)
  128.     {
  129.         base.OnMouseEnter(e);
  130.         BgColor = ColorTranslator.FromHtml("#111111");
  131.         Refresh();
  132.     }
  133.     protected override void OnMouseLeave(EventArgs e)
  134.     {
  135.         base.OnMouseLeave(e);
  136.         BgColor = ColorTranslator.FromHtml("#262626");
  137.         Refresh();
  138.     }
  139.  
  140.     protected override void OnTextChanged(EventArgs e)
  141.     {
  142.         base.OnTextChanged(e);
  143.         Invalidate();
  144.     }
  145.     protected override void OnResize(EventArgs e)
  146.     {
  147.         base.OnResize(e);
  148.         Height = 52;
  149.     }
  150.  
  151.     #endregion
  152.     #region  Constructors
  153.     public Ce_Card()
  154.     {
  155.         Height = 52; Width = 182; DoubleBuffered = true;
  156.     }
  157.     #endregion
  158.     #region Draw Control
  159.     static class DrawHelper
  160.     {
  161.         public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius)
  162.         {
  163.             GraphicsPath gp = new GraphicsPath();
  164.             gp.AddLine(x + radius, y, x + width - (radius * 2), y);
  165.             gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
  166.  
  167.             gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
  168.             gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
  169.  
  170.             gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
  171.             gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
  172.  
  173.             gp.AddLine(x, y + height - (radius * 2), x, y + radius);
  174.             gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
  175.  
  176.             gp.CloseFigure();
  177.             return gp;
  178.         }
  179.         public static GraphicsPath CreateUpRoundRect(float x, float y, float width, float height, float radius)
  180.         {
  181.             GraphicsPath gp = new GraphicsPath();
  182.  
  183.             gp.AddLine(x + radius, y, x + width - (radius * 2), y);
  184.             gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
  185.  
  186.             gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2) + 1);
  187.             gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, 2, 0, 90);
  188.  
  189.             gp.AddLine(x + width, y + height, x + radius, y + height);
  190.             gp.AddArc(x, y + height - (radius * 2) + 1, radius * 2, 1, 90, 90);
  191.  
  192.             gp.AddLine(x, y + height, x, y + radius);
  193.             gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
  194.  
  195.             gp.CloseFigure();
  196.             return gp;
  197.         }
  198.         public static GraphicsPath CreateLeftRoundRect(float x, float y, float width, float height, float radius)
  199.         {
  200.             GraphicsPath gp = new GraphicsPath();
  201.             gp.AddLine(x + radius, y, x + width - (radius * 2), y);
  202.             gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
  203.  
  204.             gp.AddLine(x + width, y + 0, x + width, y + height);
  205.             gp.AddArc(x + width - (radius * 2), y + height - (1), radius * 2, 1, 0, 90);
  206.  
  207.             gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
  208.             gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
  209.  
  210.             gp.AddLine(x, y + height - (radius * 2), x, y + radius);
  211.             gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
  212.  
  213.             gp.CloseFigure();
  214.             return gp;
  215.         }
  216.         public static Color BlendColor(Color backgroundColor, Color frontColor)
  217.         {
  218.             double ratio = 0 / 255d;
  219.             double invRatio = 1d - ratio;
  220.             int r = (int)((backgroundColor.R * invRatio) + (frontColor.R * ratio));
  221.             int g = (int)((backgroundColor.G * invRatio) + (frontColor.G * ratio));
  222.             int b = (int)((backgroundColor.B * invRatio) + (frontColor.B * ratio));
  223.             return Color.FromArgb(r, g, b);
  224.         }
  225.     }
  226.     public class FontManager
  227.     {
  228.  
  229.         public Font MyFont_Medium15;
  230.         public Font MyFont_Medium10;
  231.         public Font MyFont_Regular10;
  232.  
  233.  
  234.         public Font MyFont_Medium9;
  235.         public Font MyFont_Regular9;
  236.  
  237.  
  238.         public FontManager()
  239.         {
  240.             MyFont_Medium15 = new Font("Century Gothic", 15f);
  241.             MyFont_Medium10 = new Font("Century Gothic", 10f);
  242.             MyFont_Regular10 = new Font("Century Gothic", 10f);
  243.  
  244.             MyFont_Medium9 = new Font("Century Gothic", 9f);
  245.             MyFont_Regular9 = new Font("Century Gothic", 9f);
  246.         }
  247.  
  248.         private PrivateFontCollection privateFontCollection = new PrivateFontCollection();
  249.  
  250.         [DllImport("gdi32.dll")]
  251.         private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pvd, [In] ref uint pcFonts);
  252.  
  253.         private FontFamily LoadFont(byte[] fontResource)
  254.         {
  255.             int dataLength = fontResource.Length;
  256.             IntPtr fontPtr = Marshal.AllocCoTaskMem(dataLength);
  257.             Marshal.Copy(fontResource, 0, fontPtr, dataLength);
  258.  
  259.             uint cFonts = 0;
  260.             AddFontMemResourceEx(fontPtr, (uint)fontResource.Length, IntPtr.Zero, ref cFonts);
  261.             privateFontCollection.AddMemoryFont(fontPtr, dataLength);
  262.  
  263.             return privateFontCollection.Families.Last();
  264.         }
  265.     }
  266.     protected override void OnPaint(PaintEventArgs e)
  267.     {
  268.         base.OnPaint(e);
  269.  
  270.         Graphics G = e.Graphics;
  271.         G.SmoothingMode = SmoothingMode.HighQuality;
  272.         G.Clear(Parent.BackColor);
  273.  
  274.         StringColor = ColorTranslator.FromHtml(Titelcolor);
  275.         ThumbnailBGColor = ColorTranslator.FromHtml(thumbnailcolor);
  276.  
  277.         var BG = DrawHelper.CreateRoundRect(1, 1, Width - 3, Height - 3, 1);
  278.         var ThumbnailBG = DrawHelper.CreateLeftRoundRect(1, 1, 50, 49, 1);
  279.  
  280.         G.FillPath(new SolidBrush(BgColor), BG);
  281.         G.DrawPath(new Pen(BorderColor), BG);
  282.  
  283.         G.FillPath(new SolidBrush(ThumbnailBGColor), ThumbnailBG);
  284.         G.DrawPath(new Pen(ThumbnailBGColor), ThumbnailBG);
  285.  
  286.         if (image != null)
  287.         { G.DrawImage(image, 3, 3, 48, 47); }
  288.         if (Enabled)
  289.         { G.DrawString(Text, font.MyFont_Medium10, new SolidBrush(StringColor), new PointF(58.6f, 9f)); }
  290.         else
  291.         { G.DrawString("Wait...", font.MyFont_Medium10, new SolidBrush(StringColor), new PointF(58.6f, 9f)); }
  292.  
  293.         G.TextRenderingHint = TextRenderingHint.AntiAlias;
  294.         G.DrawString(information, font.MyFont_Regular9, new SolidBrush(ColorTranslator.FromHtml("#757B7A")), new PointF(59.1f, 26f));
  295.     }
  296.     #endregion
  297. }
  298. #endregion
  299.     #region Pens
  300.     public sealed class Pens
  301.     {
  302.  
  303.         public static Pen Red
  304.         {
  305.             get { return new Pen(Colors.Red); }
  306.         }
  307.  
  308.         public static Pen LightRed
  309.         {
  310.             get { return new Pen(Colors.LightRed); }
  311.         }
  312.  
  313.         public static Pen DarkRed
  314.         {
  315.             get { return new Pen(Colors.DarkRed); }
  316.         }
  317.  
  318.         public static Pen Blue
  319.         {
  320.             get { return new Pen(Colors.Blue); }
  321.         }
  322.  
  323.         public static Pen LighterBlue
  324.         {
  325.             get { return new Pen(Colors.LighterBlue); }
  326.         }
  327.  
  328.         public static Pen DarkBlue
  329.         {
  330.             get { return new Pen(Colors.DarkBlue); }
  331.         }
  332.  
  333.         public static Pen White
  334.         {
  335.             get { return new Pen(Colors.White); }
  336.         }
  337.  
  338.         public static Pen Silver
  339.         {
  340.             get { return new Pen(Colors.Silver); }
  341.         }
  342.  
  343.         public static Pen LightSilver
  344.         {
  345.             get { return new Pen(Colors.Gray); }
  346.         }
  347.  
  348.         public static Pen LighterSilver
  349.         {
  350.             get { return new Pen(Colors.LighterSilver); }
  351.         }
  352.  
  353.         public static Pen DarkGray
  354.         {
  355.             get { return new Pen(Colors.DarkGray); }
  356.         }
  357.  
  358.         public static Pen Gray
  359.         {
  360.             get { return new Pen(Colors.Gray); }
  361.         }
  362.  
  363.         public static Pen LightGray
  364.         {
  365.             get { return new Pen(Colors.LightGray); }
  366.         }
  367.  
  368.         public static Pen LighterGray
  369.         {
  370.             get { return new Pen(Colors.LighterGray); }
  371.         }
  372.  
  373.     }
  374.     #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement